首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cherry从两次提交中选择好的内容,然后创建一个新的第三次提交

Cherry从两次提交中选择好的内容,然后创建一个新的第三次提交
EN

Stack Overflow用户
提问于 2014-09-18 21:33:59
回答 1查看 34关注 0票数 0

情况如下:

  1. DevA对SomeFile.txt做了很好的添加,然后提交,然后推送(AAA)
  2. DevB拉,编辑了 DevA做的,提交的,然后推的(BBB)
  3. DevC退出并希望保留DevA所做的部分和DevB所做的部分。

DevC如何从AAA和BBB中选择更改来创建一个新的提交CCC?

注意事项:

  • 我们不想改写历史。
  • AAA将干净地与BBB合并。

ASCII图

代码语言:javascript
复制
CCC    (should include GoodIdeaA and GoodIdeaB)
 |
 | BBB (added GoodIdeaB, in the process deleted GoodIdeaA)
 | /
AAA    (added GoodIdeaA)

注意,BBB是通过批发copy-and-paste操作完成的。应该是通过合并完成的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-18 21:39:12

如果希望获取提交的各个部分,可以使用git cherry-pick-n选项来避免添加commit:

代码语言:javascript
复制
   -n, --no-commit
       Usually the command automatically creates a sequence of commits.
       This flag applies the changes necessary to cherry-pick each named
       commit to your working tree and the index, without making any
       commit. In addition, when this option is used, your index does not
       have to match the HEAD commit. The cherry-pick is done against the
       beginning state of your index.

       This is useful when cherry-picking more than one commits' effect to
       your index in a row.

所以就像这样:

代码语言:javascript
复制
git cherry-pick -n AAA
git cherry-pick -n BBB
# Edit, clean up
git commit -m CCC
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25922745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档