3

In my project there are a stable branch and a dev branch. Commits are cherry-picked from dev branch to stable branch.

In order to filter all commits on dev that have not been merged to stable, git cherry -v stable dev looks like a good choice. However it identifies equivalence by diff, which usually changes after resolving merge conflict during cherry-pick:

The equivalence test is based on the diff, after removing whitespace and line numbers. git-cherry therefore detects when commits have been "copied" by means of git-cherry-pick(1), git-am(1) or git-rebase(1).

I was wondering that is there any command that works like git cherry, but identifies equivalent commits by commit message?

4

3 回答 3

2

似乎没有直接的方法可以做到这一点,所以我写了一个简短的脚本:

#!/bin/bash
git cherry -v stable dev | grep + | cut -d ' ' -f 3- > /tmp/unmerged
xargs -a /tmp/unmerged  -I{} git --no-pager log stable --pretty=oneline --grep {} | cut -d ' ' -f 2- > /tmp/cherry-picked
diff /tmp/unmerged /tmp/cherry-picked

说明

git cherry -v stable dev | grep + | cut -d ' ' -f 3- > /tmp/unmerged 写入仅存在于dev分支上的提交的提交消息。这些提交包括那些已经被精心挑选并更改为stable分支的提交,我们需要在下一步中过滤掉这些提交。

xargs -a /tmp/unmerged -I{} git --no-pager log stable --pretty=oneline --grep {} | cut -d ' ' -f 2- > /tmp/cherry-picked输出来自 (1) 的提交消息,这些消息在stable. 换句话说,/tmp/cherry-picked存储所有经过精心挑选并从 更改为 的dev提交stable

最后,diff /tmp/unmerged /tmp/cherry-picked给出所有提交,dev其中没有找到具有相同提交消息的提交stable

于 2017-07-30T05:11:52.333 回答
1

如果dev没有重新设置提交,那么您可以使用git cherry-pick -x,显式标记源。不会自动使用这些信息,但是通过一些 bash fu 可以使用它。

于 2017-07-30T06:22:30.300 回答
0

你想用patch-id. 这是使用的机制git cherry

要找到等效的提交3642151运行:

git show 3642151 | git patch-id

你应该得到一个有两个哈希的行;第一个是patchid(调用它PATCHID_FROM_ABOVE

git log -p | git patch-id | grep PATCHID_FROM_ABOVE

这应该会为您提供与该 patchid 对应的所有提交的列表。

窃取自: http: //git.661346.n2.nabble.com/git-cherry-to-find-equivalent-commit-IDs-td3440883.html

于 2017-11-14T14:52:00.773 回答