通过特定的提交隔离git从一个分支到另一个分支的更改

时间:2019-02-14 20:01:20

标签: git repository rebase cherry-pick

我已经寻找了一段时间,并尝试了各种选择来寻找答案,但是我在如何实现此功能方面苦苦挣扎。我们的变更量很大,有时某些变更不会被周期批准,而其他变更则需要周期批准,因此我们的团队希望转向敏捷方法。

我们在git的存储库中拥有此当前设置:

Master  - C1           
 \         \ 
  \      Release1 - C1
   \        
Develop - C1 - C2 - C3 - C4 - C5 - C6

我们已经在某个时间点从Master创建了Develop,并且第一个Release都处于同一提交级别。然后,Develop获得了连续的提交流程,其中一些通过了测试,而有些则没有通过。我们如何才能将特定的提交分别从Develop移到Release1?

类似这样的东西:

Master  - C1 -   -    -    -    -  Master
 \         \                        /
  \      Release1 - C1 - C3 - C5 - C2 
   \        
Develop - C1 - C2 - C3 - C4 - C5 - C6 - C7 - C8 - C9

例如,我尝试在C3上进行樱桃挑剔,但它带来了C2。任何帮助将不胜感激。

编辑:在此处,注释是步骤和输出。我试图选择一个或两个提交,并始终获得相同的结果。我做错了吗?

 ~/git/cherrypick_test (Develop)
$ git log
commit 9d296fb748731c9252b55bcb52a14d2638112bd1 (HEAD -> Develop, origin/Develop)
         Change3 123
commit 3e01cdf9d11043fd58e4684742a3f69ee350b037
         Change 125
commit 62ab4c96a767113d22fb2f78d20b6d72587fff86
         Change 124
commit c28ce2ea753611f5f5b559f4f6598b2584f3e2f6
         Change2 123
commit 7763c4ef9c01b7b7c5189d9b9fa2cedaeff62d68
         Change 123
commit 2a60e37761ed3de745e760d5a472fd593c4c9b26 (origin/release/Sprint1, release/Sprint1)

$ git checkout release/Sprint1
Switched to a new branch 'release/Sprint1'
Branch 'release/Sprint1' set up to track remote branch 'release/Sprint1' from 'origin'.

~/git/cherrypick_test (release/Sprint1)
$ git log
commit 2a60e37761ed3de745e760d5a472fd593c4c9b26 (HEAD -> release/Sprint1, origin/release/Sprint1)

~/git/cherrypick_test (release/Sprint1)
$ git cherry-pick 3e01cdf9d11043fd58e4684742a3f69ee350b037 62ab4c96a767113d22fb2f78d20b6d72587fff86
error: could not apply 3e01cdf9d... 
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

我不明白为什么会有冲突,因为这只是将代码添加到单个文件中进行演示,但是从SourceTree打开文件后,我在合并冲突中看到以下内容:

<<<<<<< HEAD
=======
//adding change 123
//second change 123

//change 124

//change 125

>>>>>>> 3e01cdf9d... SG7-125 test cherry picking function

在此示例中,我应该只获得124和125,但是两个123都与它们一起出现。

1 个答案:

答案 0 :(得分:0)

执行此操作

git checkout Release1
git cherry-pick C1 C3 C5 C2

然后进行简单的合并。