开发者

split repo using git filter-branch: how to recover history from renamed/moved files?

开发者 https://www.devze.com 2023-01-31 09:58 出处:网络
Disclaimer: I\'ve seen Detach (move) subdirectory into separate Git repository but it doesn\'t fully answer the question.

Disclaimer: I've seen Detach (move) subdirectory into separate Git repository but it doesn't fully answer the question.

I've migrated a project from svn to git. When it lived in svn, some files were moved and/or renamed.

After the git migration, some of the commits are only visible with git log --follow

so:

the git s开发者_StackOverflowtructure looks like:

MyMainRepo/
.git/
XYZ/
ABC/myFile.txt

git log ABC/myFile.txt show: - commit1 - commit2

git log --follow ABC/myFile.txt shows: - commit1 - commit2 - commit3 (the ABC directory didn't exist back then) ...

now, when splitting the git repo to have a distinct ABC git repo: git log --follow ABC/myFile.txt now lost the older history and I just have :

  • commit1
  • commit2

What I would like:

  • split ABC from MyMainRepo,
  • not losing the history

Any help is welcome :)


I just came across the same problem, and was unable to get a complete history of the moved folder, even with index-filter.

My workaround is to do a separate subdir export of the folder (ABC) that has been moved at a point before it was moved, and then graft the history of this repository in the new one.

Let's say ABC used to be called MNO. I clone MyMainRepo, reset to a version when MNO still existed (before it was renamed to ABC). I do a filter-branch with subdir to get a repository called "MNO".

Inside ABC, I do a git fetch ../MNO.

I then enter the commit of when the contents were moved into ABC (this will be the first commits with the contents in repo ABC) PLUS the last commit in the MNO repo into .git/grafts.

Now I can do git log on files inside ABC, and see history tracing all the way through how it was in MNO. Next step is to do another filter-branch to make it a permanent graft, etc. I've made a screencast that demonstrates grafting here (although the context is a bit different):

http://blog.tfnico.com/2010/10/gitsvn-6-grafting-together-svn-history.html

Note that this has to be done on a per-moved-folder basis, it's a lot of work, and you end up with a merge commit for each case. But git log works.

I'm writing this in a bit of a hurry, but if anyone is interested in trying this approach, let me know, and I'll try to clear it up a bit, and show some more concrete examples.


Rather than a subdirectory filter, perhaps an index-filter with a recipe similar to your log evaluation would be what you need to follow the renames back in history. I've got a working example of an index filter here and documentation for how to use it here.

0

精彩评论

暂无评论...
验证码 换一张
取 消