How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

Viewed 13840

I have a project under git. One day I moved all project files from current directory to foo/bar/ under the project. I did it using git mv. Then I added some more files and did some changes to already existing files.

As a result, now when I look at the history of foo/bar/file.c, I can only see changes that I did after I moved the file.

I tried to fix this in various ways (filter-branch with subdirectory filter, etc), but nothing helped, so I am pretty stacked here. I'll appreciate any help that you can give me. Thanks!

3 Answers

Install git-filter-repo:

git clone https://github.com/newren/git-filter-repo/

Add the git-filter-repo executable to your $PATH (see INSTALL.MD for other options):

# this is just an example, you probably want to edit bashrc,
# or add a symlink to ~/bin or /usr/local/bin
PATH=$PATH:${PWD}/git-filter-repo

Now cd to the git repo that you want to modify, and run:

git filter-repo --to-subdirectory-filter foo/bar
Related