Let's say I want to rewrite Git history, moving all the contents of /foo/bar
to /baz/quux
for all the past commits; running on Windows.
I made a sample repo with two commits in /foo/bar
and nothing more:
git clone https://github.com/jakub-g/filter-branch-test
Let's put the script like below one folder up from my Git repo and run it (similar things are mentioned in many places on SO, including https://stackoverflow.com/a/13590229).
#!/bin/bash
PATH_TO_GIT_REPO='./filter-branch-test'
REWRITE_FROM='foo/bar/'
REWRITE_TO='baz/quux/'
cd ${PATH_TO_GIT_REPO} &&
git filter-branch -f --index-filter \
'git ls-files -s | sed "s-\t${REWRITE_FROM}-\t${REWRITE_TO}-" \
| GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info \
&& mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' &&
cd -
When I run it:
bash ./runFilterBranch.sh
The output is:
...
WARNING: Ref 'refs/heads/master' is unchanged
and nothing happened, I still have old paths.
When I run git ls-files -s | sed "s-\t${REWRITE_FROM}-\t${REWRITE_TO}-"
in master, I see that sed does the replacements correctly.
What am I missing here?