Split repo with git filter-branch: how to restore history from renamed / moved files?

Disclaimer: I saw the Detach (move) subdirectory in a separate Git repository , but it does not fully answer the question.

I migrated the project from svn to git. When he lived in svn, some files were moved and / or renamed.

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

So:

The structure of Git is as follows:

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

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

git log --follow ABC/myFile.txt shows: - commit1 - commit2 - commit3 (then the ABC directory did not exist) ...

now that the git log --follow ABC/myFile.txt repo split should have a distinct ABC git log --follow ABC/myFile.txt repo: git log --follow ABC/myFile.txt now has lost the older story and I just have:

  • commit1
  • commit2

What I would like:

  • beat ABC from MyMainRepo,
  • don't lose the story

Any help is appreciated :)

+4
source share
2 answers

I ran into the same problem and could not get the full history of the moved folder even with the index filter.

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

Suppose the ABC was called MNO. I cloned MyMainRepo, reset to the version when MNO still existed (before it was renamed ABC). I am doing a filter branch with subdir to get a repository called "MNO".

Inside ABC, I am doing git fetch ../MNO .

Then I go into commit when the contents have been moved to ABC (this will be the first commit with contents in the ABC repo). PLUS is the latest commit to the MNO repository in .git/grafts .

Now I can execute git to enter files inside ABC, and also view the history, tracking everything, as it was in MNO. The next step is to make another branch of the filter to make it a permanent transplant, etc. I did a screencast demonstrating the vaccination here (although the context is slightly different):

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

Please note that this needs to be done in the redirected folder, this is a lot of work, and in the end you get a merge commit for each case. But git log works.

I write this in a hurry, but if someone is interested in trying this approach, let me know and I will try to clarify it a bit and show some specific examples.

+1
source

Instead of a subdirectory filter, perhaps an index filter with a recipe similar to your journal rating will be what you need to follow the renaming in the story. I have a working example of an index filter here and documentation for use here .

0
source

Source: https://habr.com/ru/post/1332598/


All Articles