git: Keep changelog for file when moving to a different repository
Assume you want to transfer the history of filename.conf
from one source repository to another receiving repository. I think the strategy you want to follow is:
- In the source repository, create a branch of commits which are re-written to contain only
filename.conf
. - Merge the independent line of commits into a normal branch in the receiving repository.
Definitely make backups of your repositories before you do this!
In the source repository, use filter-branch to rebuild the history removing everything except filename.conf
.
git checkout -b filtered-commits
git filter-branch -f --prune-empty --tree-filter 'find . -not -name filename.conf -exec rm {} \;' filtered-commits
Then, in the receiving repository:
git pull path/to/source/repo
If you also need to move the path that filename.conf
is in within the repository, you'll probably need to use the --subdirectory-filter
option on git filter-branch
.