码迷,mamicode.com
首页 > 其他好文 > 详细

多个git项目库之间的git cherry-pick代码同步

时间:2020-04-18 09:18:28      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:tomat   call   checkout   struct   bsp   项目库   git fetch   mail   conf   

这段时间做项目间的代码分离,从git上的A库  fork一份到B库,然后A库和B库就各自独立的需求代码开发。

这样A库和B库的开始时代码基本相同,但遇到一个问题,有些时候A库的代码BUG修改,需要在B库中再修改一下,不太方便。

因此,就试一下用cherry-pick是否可行。

 

经过翻看一些前辈文章并开始尝试,(以把A库的release的某次提交commit-->commit id is XXXXX,提交到B库的release分支上为例)步骤如下:

  1、把代码切到B库的release分支上,为防止出问题,建议先拉取一个备份的分支。

  2、本地添加另一个仓库A

 Zxxxxx5:B 1$ git remote add zhorigin http://git.xxxx.com/A.git

通过git remote -v 可以查看是否添加成功
Zxxxxx5:B 1$ git remote -v
origin  http://git.xxxx.com/B.git (fetch)
origin  http://git.xxxx.com/B.git (push)
zhorigin        http://git.xxxx.com/A.git (fetch)
zhorigin        http://git.xxxxcom/A.git (push)

  3、Zxxxxx5:B 1$ git fetch zhorigin  这时会把远程A库的分支信息同步到本地

  4、这时候就可以cherry-pick了,遇到相关的提示,根据提示操作就行了

    Zxxxxx5:B 1$ git cherry-pick ac50e25bf

on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
    git config --global --edit
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author

---------------------------------------------------------------
---------------------------------------------------------------

Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author

 

 

 5、上面的提示,操作完后,就可以git push了,这时候,神奇的一幕出现了,把修复A库的BUG分支 clone了一份到B库上了,(如果在A库的release分支直接修改的,可能就直接push到B库的release了,有兴趣的可以试一下)

Zxxxxx5:B 1$ git push
Enumerating objects: 69, done.
Counting objects: 100% (69/69), done.
Delta compression using up to 8 threads
Compressing objects: 100% (20/20), done.
Writing objects: 100% (39/39), 4.01 KiB | 2.00 MiB/s, done.
Total 39 (delta 13), reused 10 (delta 3)
To http://git.xxxx.com/B.git
   ccccc..yyyyyy  bugfix-branch-xxxx-A -> bugfix-branch-xxxx-A

6、至此A库的BUG修改分支在B库已经有了,之后的流程就简单了,和普通的cherry-pick流程一样了

   本地确保切到B库的release

  Zxxxxx5:B 1$ git checkout release
  Zxxxxx5:B 1$ git cherry-pick yyyyyy

  Zxxxxx5:B 1$ git push

 

备注:

     这里面有一些细节,很有意思,比如为什么A库clone出一个分支到B库,新的分支版本的起始commit id为什么是 ccccc等等

 

多个git项目库之间的git cherry-pick代码同步

标签:tomat   call   checkout   struct   bsp   项目库   git fetch   mail   conf   

原文地址:https://www.cnblogs.com/xuzhujack/p/12724115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!