部分樱桃采摘与Git的承诺 [英] Partly cherry-picking a commit with Git
问题描述
我正在处理2个不同的分支:发布和开发。
我注意到我仍然需要将提交给发布分支的一些更改整合回开发分支。
问题是我不需要所有的提交,只有某些文件中的某些宏,所以简单的
git cherry-pick bc66559
不做招。
当我做一个
git show bc66559
我可以看到差异,但并不知道将这部分应用于当前工作树的好方法。
$ c>( -p
是 - patch
的同义词)。这提供了一种互动的方式来检查内容,让你决定是否每个人都应该进去,甚至让你手动编辑修补程序(如有必要)。
使用它与樱桃挑选组合:
git cherry-pick -n< commit> #获取你的补丁,但不要提交(-n = --no-commit)
git reset#停止从樱桃选择提交中的更改
git add -p#使所有选项添加你想要的改变)
git commit#make commit!
(感谢Tim Henigan提醒我git-cherry-pick有一个--no-commit选项,并感谢Felix Rabe指出你需要重置!如果你只想让一些东西脱离提交,你可以使用 你当然可以提供指向 如果你真的想要一个 这会将当前提交与您指定的提交进行比较,并允许您应用该差异个别。如果您所提交的提交合并了您不感兴趣的部分提交中的冲突,则此选项可能更有用。(但请注意, I'm working on 2 different branches: release and development. I noticed I still need to integrate some changes that were committed to the release branch back into the development branch. The problem is I don't need all of the commit, only some hunks in certain files, so a simple does not do the trick. When I do a I can see the diff but don't really know a good way of applying that partially to my current working tree. The core thing you're going to want here is To use it in combination with cherry-pick: (Thanks to Tim Henigan for reminding me that git-cherry-pick has a --no-commit option, and thanks to Felix Rabe for pointing out that you need to reset! If you only want to leave a few things out of the commit, you could use You can of course provide specific paths to If you really want a That will diff the current commit against the commit you specify, and allow you to apply hunks from that diff individually. This option may be more useful if the commit you're pulling in has merge conflicts in part of the commit you're not interested in. (Note, however, that 这篇关于部分樱桃采摘与Git的承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git reset< path> ... <
add -p
如果有必要。如果你从一个补丁开始,你可以用 apply
替换 cherry-pick
。
git cherry-pick -p< commit>
选项不存在),你可以使用
git checkout -p< commit>
checkout
不同从> cherry-pick
: checkout
尝试应用< commit>
的内容, cherry-pick
应用指定提交从它的父级的差异,这意味着 checkout
可以应用的不仅仅是那个提交,这可能比你想要的要多。)git cherry-pick bc66559
git show bc66559
git add -p
(-p
is a synonym for --patch
). This provides an interactive way to check in content, letting you decide whether each hunk should go in, and even letting you manually edit the patch if necessary.git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit)
git reset # unstage the changes from the cherry-picked commit
git add -p # make all your choices (add the changes you do want)
git commit # make the commit!
git reset <path>...
to unstage just those files.)add -p
if necessary. If you're starting with a patch you could replace the cherry-pick
with apply
.
git cherry-pick -p <commit>
(that option does not exist), your can usegit checkout -p <commit>
checkout
differs from cherry-pick
: checkout
tries to apply <commit>
's contents entirely, cherry-pick
applies the diff of the specified commit from it's parent. This means that checkout
can apply more than just that commit, which might be more than you want.)