开发者

git-cherry seems like not working for disordered merges

I tried to use git cherry-pick for merging some commits from master and then git-cherry to determine what commits currently merged. It works fine while I merge it in the order it's on master, but when I skip merging one of the commits it doesn't show me the next merged. Example below:

$ git branch
* branch
  master
$ git log --oneline
46aad17 comment4
56e43b0 comment3
26370b3 comment2
6192fa4 comment1

$ git cherry -v branch master
- 5c5e979707cd6a77e开发者_如何学Pythonf3ae79627cdd211cad86a28 comment3
- ee0386c78d9e6d21dce7a8bac8e40beef73fb993 comment4
+ 9495c94ece440d9a05c3218f88d1b72a7fd67664 unmerged # this wasn't merged
+ 235b0822f08f351264071e7b2500caa9af997fb8 comment2

The question is why comment2 shown as unmerged while it's shown merged in log?


Just as a preliminary note, it's a bit confusing to describe these as merges - they're just cherry-picks, i.e. commits created by applying the patch introduced by another commit onto a new parent.

git cherry looks at the patch which a commit introduces, and tests to see if there is already a similar patch that has been introduced in the upstream branch. As documented in the git cherry man page, it decides whether two patches are the same based on whether they have the same "patch ID", which is described as:

A "patch ID" is nothing but a SHA1 of the diff associated with a patch, with whitespace and line numbers ignored. As such, it’s "reasonably stable", but at the same time also reasonably unique, i.e., two patches that have the same "patch ID" are almost guaranteed to be the same thing.

IOW, you can use this thing to look for likely duplicate commits.

So, I suspect that if the commit associated with comment2 isn't detected as having already been applied that's because the patch IDs are different. That might, for example, be because you had to resolve a conflict when cherry-picking the commit associated with comment2. That might well mean the patches that the commits introduced ended up being different. You can see if that is right by comparing the output of these two commands:

git show 26370b3
git show 235b082
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜