找到 "rebase -m" 起点

find the "rebase -m" starting point

最近我在用

git checkout dev_branch -b merge_branch
git rebase -m merge_branch master
git checkout master
git rebase merge_branch

进行合并变基。如帮助文档所示,merge_branch 首先重置为 master 的 HEAD,然后将原始 dev_branch 中的新提交逐一回放到新分支。

几天后我想找到这个变基合并的 "starting point" 在哪里。我可以使用

在 dev_branch 中找到第一个增量提交
git merge-base master dev_branch // Get an SHA_root of the common ancestor
git log --reverse -1 <SHA_root>..dev_branch  // Get an SHA_delta of the first delta commit

但我找不到找到合并版本的方法

git branch --contains <SHA_delta>

但是发现只有"dev_branch",没有"master_branch",其实已经合并了

换句话说,不同parent的同一个commit(比如使用cherry-pick的情况)有不同的SHA。有没有办法 git 可以将它们识别为实际上相同?

这就是 git cherry 所做的。

In a situation where topic consisted of three commits, and the maintainer applied two of them, the situation might look like:

$ git log --graph --oneline --decorate --boundary origin/master...topic
* 7654321 (origin/master) upstream tip commit
[... snip some other commits ...]
* cccc111 cherry-pick of C
* aaaa111 cherry-pick of A

[… snip a lot more that has happened …]

| * cccc000 (topic) commit C
| * bbbb000 commit B
| * aaaa000 commit A
|/
* 1234567 branch point

In such cases, git cherry shows a concise summary of what has yet to be applied:

$ git cherry origin/master topic
- cccc000... commit C
+ bbbb000... commit B
- aaaa000... commit A

Here, we see that the commits A and C (marked with -) can be dropped from your topic branch when you rebase it on top of origin/master, while the commit B (marked with +) still needs to be kept so that it will be sent to be applied to origin/master.