简体   繁体   English

将一个仓库中的所有提交应用于另一个仓库

[英]Apply all commits from one repo to another

Context: My job decided to switch from subversion to git. 上下文:我的工作决定从Subversion切换到git。 They have 5 svn repos that need to be converted, 4 of which are small and can be migrated with git-svn in under an hour. 他们有5个需要转换的svn仓库,其中4个很小,可以在一个小时内用git-svn迁移。 The last is much bigger and git-svn runs for days and eventually crashes, so i've been experimenting with other tools like subgit, svn2git, KDE's svn2git, etc. All of them fail at the same point, a revision over a year ago, and crash. 最后一个更大,并且git-svn运行了好几天,最终崩溃了,所以我一直在尝试其他工具,例如subgit,svn2git,KDE的svn2git等。它们都在同一时间失效,是一年多以前的修订,然后崩溃。

KDE's svn2git has been the fastest and most effective so far, and its rules have allowed me to create two git repos: one with all the commits before the problem, and one with all the commits after. 到目前为止,KDE的svn2git是最快,最有效的,它的规则允许我创建两个git repos:一个包含问题之前的所有提交,一个包含问题之后的所有提交。 Now i need to correctly merge them into one git repo. 现在我需要正确地将它们合并到一个git repo中。

I know how to add one repo as a remote of another and cherry pick the commits over ( git: Apply changes introduced by commit in one repo to another repo ), but I need a way to do it over the entire repo and all its branches. 我知道如何将一个存储库添加为另一个存储库的远程对象,并从中挑选提交内容( git:将由一个存储库中的提交所引入的更改应用于另一个存储库 ),但是我需要一种方法来对整个存储库及其所有分支执行此操作。

How can i apply all of the commits of one repo on top of another? 我如何将一个回购的所有提交应用于另一个?

Edit: I'm looking to do something similar to what git rebase does so that the history is complete and accurate across the entire repository 编辑:我正在寻找与git rebase相似的方法,以便整个存储库中的历史记录完整且准确

You should be able to do it following instructions in this link: http://blog.dynamic50.com/2009/11/26/moving-your-git-repos-and-all-branches-to-a-new-remote-repository/ 您应该能够按照此链接中的说明进行操作: http : //blog.dynamic50.com/2009/11/26/moving-your-git-repos-and-all-branches-to-a-new-remote -存储库/

To sum up, track locally the old branches, add the new remote and then push everything to it. 总结一下,在本地跟踪旧的分支,添加新的遥控器,然后将所有内容推送到其中。

How about this: (Pardon me if it sounds dumb) 怎么样:(如果听起来很蠢,请原谅我)

Assumption: You have two repositories with all commits on one branch. 假设:您有两个存储库,所有提交都在一个分支上。

  1. Fetch one repository into the other. 将一个存储库提取到另一个存储库中。 (now you have two disconnected branches) (现在您有两个断开连接的分支)
  2. Rebase one branch over the other 在一个分支上建立另一个分支

The awesome guys at Github gave me an answer over email. Github上很棒的家伙通过电子邮件给了我一个答案。

  1. Fetch the earlier part of the git history into the Git repository containing the later part of the history: 将git历史记录的较早部分提取到包含历史记录较后部分的Git存储库中:

$ cd recenthistory $ git fetch ../oldhistory 'refs/*:refs/remotes/oldhistory/*'

  1. For each branch that appears both in the earlier and the later part of the history: 对于同时出现在历史记录的前半部分和后半部分的每个分支:

    • Find the oldest commit on the branch in the "recent" history. 在“最近”历史记录中找到分支上最古老的提交。 This should be an orphan commit (ie, have no parents) so it should appear alone on the last line of the output from this command: 这应该是一个孤儿提交(即没有父母),因此它应该单独出现在此命令的输出的最后一行:

$ git rev-list --topo-order --parents refs/heads/$BRANCH | tail [...] bf0c6e839c692142784caf07b523cd69442e57a5 e497ea2a9b6c378f01d092c210af20cbee762475 e497ea2a9b6c378f01d092c210af20cbee762475 8bc9a0c769ac1df7820f2dbf8f7b7d64835e3c68 8bc9a0c769ac1df7820f2dbf8f7b7d64835e3c68 e83c5163316f89bfbde7d9ab23ca2e25604af290 e83c5163316f89bfbde7d9ab23ca2e25604af290

  • Create a graft to make it look like this commit actually has the tip of the corresponding branch in the old history as its parent: 创建一个嫁接,使其看起来像这样的提交实际上具有旧历史中相应分支的尖端作为其父:

$ echo "e83c5163316f89bfbde7d9ab23ca2e25604af290 $(git rev-parse "refs/remotes/oldhistory/$BRANCH")" >>.git/info/grafts

  1. After you have completed step 2 for all branches in your repository, use git filter-branch to make the grafts permanent: 完成存储库中所有分支的第2步后,请使用git filter-branch来使嫁接永久化:

$ git filter-branch --tag-name-filter cat -- --branches --tags Verify that the history is correct.

  1. Push the resulting history to your GitHub repository. 将结果历史记录推送到您的GitHub存储库。 Please note that if you already have branches or tags in your GitHub repository, this will overwrite them!: 请注意,如果您在GitHub存储库中已经有分支或标记,则将覆盖它们!:

$ git push origin --force --all $ git push origin --force --tags

  1. Clone a fresh copy from GitHub and double-check that everything is OK. 从GitHub克隆一个新副本,然后仔细检查一切正常。

  2. Delete the recenthistory and oldhistory repositories (perhaps making backups first). 删除最新历史记录和旧历史记录存储库(也许首先进行备份)。 The histories in these repositories is not compatible with the history in GitHub, so you want to be sure not to do any further work in them. 这些存储库中的历史记录与GitHub中的历史记录不兼容,因此您要确保不要在其中进行任何进一步的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM