Using git fast-export to export a repo starting at a given commit

余生颓废 提交于 2020-01-02 10:24:29

问题


I am currently trying to merge the current repo at work with one that was converted from my work's old svn repo. I want the new repo (we'll call it A) to be merged with the current working repo (B).

B is the result of a failed attempt to convert the svn repo to git with the history intact. A is the second attempt. If I just merge B with A, there will be duplicate commits for everything in the old svn repo. I would like to only include the history from B that happened after the last svn commit.

I am looking at git-fast-export, but I haven't found any documentation that would help me. Should I use git-fast-export, or is there a better way? How would I use git-fast-export or something else to do the merge?


回答1:


If you have only one branch to merge back, then another way would be to use grafts (see "gardening tips -- grafting branches"):

  • Add B as a remote for A: "remoteB",
  • find the SHA1 of A representing the SVN repo converted (and from which new commits were done): "SHA1-A",
  • find the SHA1 of B representing the next commit after the SVN repo converted (that is, the first of the new commits done from the failed SVN conversion): "SHA1-B",
  • See this example:

You can override parents of a commit in Git using a file called grafts, which needs to reside in .git/info/.
It consists of several lines with commit hashes separated by a space character, where the first hash is the commit you want to define parents for, and the following hashes are the parents.

Note: you must use full hashes, not abbreviated ones.

To fix the history above, we must define the parents in .git/info/grafts:

SHA1-B SHA1A
  • Make that graft permanent:

    git filter-branch --tag-name-filter cat -- --all
    
  • Make a local branch reference the HEAD of B branch you just grafte,.

    git branch Bmaster remoteB/master
    
  • Merge your two branches (and you can remove the 'remoteB' repo, you don't need it anymore).



来源:https://stackoverflow.com/questions/19016375/using-git-fast-export-to-export-a-repo-starting-at-a-given-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!