Filter branch only for the current branch and current director

I have a local branch with several commits. Now I need to rewrite all these commits and change the file name, but only in one specific directory. I don’t want any changes to be made outside my local branch.

Running git filter-branch 'some command' master..HEAD in this directory gives me

 You need to run this command from the toplevel of the working tree. 

Of course, I can run this from the top level, but it will force me to write my script with the outline of the directory that I really want to change, and in the end I would like to run the same script in a couple of directories, not knowing that there is a full path.

Is there a way to start the filter branch and have the script have the current directory as a working directory?

+4
source share
1 answer

No no. But just make your script a parameter, and then run it in your top layer:

 git filter-branch 'yourscript the/sub/directory' master..HEAD 
+3
source

All Articles