I want to rewrite history and move all files and folders in a certain folder 2 folders up for all branches.
My repo looks like:
- src
- v105
- src
- files
- folders
- tools
- lib
I want it to be:
- src
- files
- folders
- tools
- lib
I know how to rewrite history for removing files recursively in a folder
git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatched somefolder/somefolder'
--prune-empty --tag-name-filter cat -- --all
I also know the git mv
command.
Using the following command the files and folders are all moved to the correct folder. The first patterns matches all files and folders within the provided folder. The second pattern matches all files and folders starting with a dot.
git mv src/v105/src/* src/v105/src/.[^.]* src
However when I want to use this command with the rewrite history command it doesn't work.
git filter-branch --force --index-filter 'git mv src/v105/src/* src/v105/src/.[^.]* src --cached --ignore-unmatched'
--prune-empty --tag-name-filter cat -- --all
Because the src folder does not exist in all cases in my commit history it tells me it can't find the src dir. Any ideas how to solve this?
UPDATE
git filter-branch --force --index-filter 'if [-d 'src/v105/'] then git mv src/v105/src/* src/v105/src/.[^.]* src fi'
--prune-empty --tag-name-filter cat -- --all
results in unexpected end of file.