任何人都可以解释什么git cherry-pick< sha>呢? [英] Can anyone explain what git cherry-pick <sha> does?

查看:109
本文介绍了任何人都可以解释什么git cherry-pick< sha>呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在我经历了几个月后,我想要在我的另一个本地分支[包含abc.cpp,def.cpp]使用这些更改,但在我当前的分支中升级abc.cpp。那么,如果我选择了樱桃,那么它会将旧的abc.cpp的变化整合到新的abc.cpp [最近的工作目录副本]中?

解决方案 Git-cherry-pick(1)手册页说:


给定一个或多个现有的提交,应用更改每一个
介绍,为每个记录一个新的提交。这需要你的工作
树是干净的(不需要修改HEAD提交)。

那么 git cherry-pick 会将一个分支提交到另一个分支,但不会保留原来的历史或来自其他分支的祖先,因为合适的合并将会执行。 / p>

将其视为应用一系列选定的补丁,而不是将两个历史分支完全合并。显然,如果你倾向于做出非常小的原子提交,那么采摘樱桃看起来就像应用一个写得很好的补丁。但是,由于您没有共同祖先的方式来处理合并或重新绑定,因此如果您的提交不是很小且孤立的话,您可能会遇到更多冲突。



樱桃采摘是否是一个好主意很大程度上取决于你如何组织你的提交。如果它不适合你,你可以使用 git format-patch git apply 相反。


As my concern here is, I have old commit in my another local branch [contains abc.cpp, def.cpp].

Now after few months I want use those changes, but in my current branch abc.cpp is upgraded. So is it like if I cherry pick then it will integrate changes of old abc.cpp into new abc.cpp [recent working directory copy]?

解决方案

The git-cherry-pick(1) man page says:

Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).

In plain English, this means that git cherry-pick applies commits from one branch to another, but does not preserve the original history or ancestry from the other branch in the way that a proper merge would do.

Think of it as applying a series of selected patches, rather than a full merge of two branches of history. Obviously, if you tend to make very small, atomic commits then cherry-picking looks exactly like applying a well-written patch. However, since you don't have common ancestors the way you do with merge or rebase, you may have a lot more conflicts to resolve if your commits aren't small and isolated.

Whether or not cherry-picking is a good idea is highly dependent on how you structure your commits. If it doesn't work for you, you can always do things more manually with git format-patch and git apply instead.

这篇关于任何人都可以解释什么git cherry-pick< sha>呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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