剪切后连接git历史记录 [英] Connect git historys after cut

查看:120
本文介绍了剪切后连接git历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的两个存储库来自同一项目.我在提交3之后进行了历史记录剪切,现在仅与Repo ProjectnameWorking 一起使用.

My two repos are from the same project. I make a history cut after commit 3 and work now only with Repo ProjectnameWorking.

git log 回购"ProjectnameArchiv":

git log Repo "ProjectnameArchiv":

30114b2afac5d1c5a968441151ee8f91fc015ff3 4
9aa472d04501a14b5b704fde32445461f99f539a 3
1d0e5abe5daf60c0d86819938ba1aefd44b87ff5 2
766f4880e8ccf61bdc718dfae62466f800ae8119 1

git log 回购"ProjectnameWorking":

git log Repo "ProjectnameWorking":

2932c4b8ea681f0a97bf151ccc46d2044e8e5a50 5
27ec1a4618f1bf0025b8ba83fd69c2607cdf78d4 4


是否有一种方法可以同时连接以后的历史记录和& projectfiles到一个?


Is there a way to connect later both historys & projectfiles to one?

git log 回购项目名称"

git log Repo "Projectname"

2932c4b8ea681f0a97bf151ccc46d2044e8e5a50 5
27ec1a4618f1bf0025b8ba83fd69c2607cdf78d4 4
9aa472d04501a14b5b704fde32445461f99f539a 3
1d0e5abe5daf60c0d86819938ba1aefd44b87ff5 2
766f4880e8ccf61bdc718dfae62466f800ae8119 1


  • 在回购"ProjectnameArchiv"上提交4-从剪切中获取新哈希

推荐答案

是的,可以,但是其中一个项目的SHA将会更改:

Yes, that is possible, but the SHAs of one of the projects will change:

  • 创建一个公共的远程存储库:

  • Create a common remote repository:

/some/other/path> git init . --bare

  • ProjectnameArchiv中的9aa472d04501a14b5b704fde32445461f99f539a处创建分支并将其推送到远程:

  • Create a branch in ProjectnameArchiv at 9aa472d04501a14b5b704fde32445461f99f539a and push it to the remote:

    ProjectnameArchiv> git branch merge-base 9aa472d04501a14b5b704fde32445461f99f539a
    ProjectnameArchiv> git remote add origin file:///some/other/path
    ProjectnameArchiv> git push --all
    

  • 在另一个存储库中执行相同的操作,但获取而不是推送:

  • Do the same in the other repo but fetch instead of push:

    ProjectnameWorking> git branch working-top 2932c4b8ea681f0a97bf151ccc46d2044e8e5a50
    ProjectnameWorking> git remote add origin file:///some/other/path
    ProjectnameWorking> git fetch origin
    

  • cherry-pick 第一次进入归档分支的工作提交:

  • cherry-pick the first working commit into the archive branch:

    ProjectnameWorking> git checkout -b archive origin/merge-base
    ProjectnameWorking> git cherry-pick 9aa472d04501a14b5b704fde32445461f99f539a
    

  • 如果提交的次数很少,则可以继续进行挑选,但是对于较大的提交, rebase-ing 将工作分支的其余部分转移到archive分支的速度更快:

  • If you have only a few commits you can continue cherry-picking, but for a larger number, rebase-ing the rest of the work branch onto the archive branch is faster:

    ProjectnameWorking> git rebase --onto archive 9aa472d04501a14b5b704fde32445461f99f539a working-top
    

    您可以添加git的-i选项,以在启动前检查它的运行情况,如果出现问题,则中断该过程.

    You might add git’s -i option to check what it is doing before it starts, and interrupt the process if something went wrong.

    之后,将工作存储库中的更改添加到存档存储库中,但是它们获得了新的SHA.

    After that, the changes of the working repository are added to the archive repository but they get new SHAs.

    这篇关于剪切后连接git历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆