我有两个分支devel和next。在devel中,我有一个或多或少巨大的提交量。一些提交将在接下来被选中。此外,我还添加了一些提交到下一个合并到devel。

现在我想看看在下一步中缺少了什么,这样我就可以在将更改带到下一步之前详细地测试更改。我现在的问题是,我怎么能看到哪些提交是在devel而不是在next?


当前回答

如何

git log next..devel

结果类似于Byran的答案(不同的提交顺序),但我们的两个答案都会在分支之间产生不同的提交,而不是只显示一个分支中有什么而另一个分支中没有什么。

其他回答

很少使用的命令git cherry (docs)显示还没有被选中的提交。

简而言之:

git cherry <feature-branch> [base-branch]
# Checkout the base branch
git checkout main

# Diff against the target branch
git cherry -v next

# Diff against the target branch, without switching
git cherry -v next main

示例输出:

+ 492508acab7b454eee8b805f8ba906056eede0ff feat: make bazzable
- 5ceb5a9077ddb9e78b1e8f24bfc70e674c627949 hotfix: off-by-one
+ b4459544c000f4d51d1ec23f279d9cdb19c1d32b feat: add bar
+ b6ce3b78e938644a293b2dd2a15b2fecb1b54cd9 feat: add foo

+表示提交只在next中,而不在main中 -表示提交在两个分支中

如果你希望提交时不带主题行,可以删除-v:

+ 492508acab7b454eee8b805f8ba906056eede0ff
- 5ceb5a9077ddb9e78b1e8f24bfc70e674c627949
+ b4459544c000f4d51d1ec23f279d9cdb19c1d32b
+ b6ce3b78e938644a293b2dd2a15b2fecb1b54cd9

同样,你也可以用它来获得一个不错的不同提交的列表,这些提交没有在分支之间共享:

git log --left-right --graph --cherry-pick --oneline main...next

示例输出:

> 492508ac (HEAD -> next) feat: make bazzable
> 5ceb5a90 hotfix: off-by-one
> b4459544 feat: add bar
> b6ce3b78 (origin/add-foo, add-foo) feat: add foo

关键字是——精心挑选

——择优挑选

Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference. For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right, like the example above in the description of that option. It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.

正如在评论中提到的,最新版本的git添加了——cherry-mark:

——cherry-mark

比如——cherry-pick(见下文),但是用=标记等价的提交而不是省略它们,用+标记不等价的提交。

如何

git log next..devel

结果类似于Byran的答案(不同的提交顺序),但我们的两个答案都会在分支之间产生不同的提交,而不是只显示一个分支中有什么而另一个分支中没有什么。

要获得未集成到发布分支(下一个)的提交列表,您可以使用:

git rev-list --reverse --pretty="TO_TEST %h (<%ae>) %s" --cherry-pick --right-only origin/release_branch...origin/development_branch | grep "^TO_TEST " > NotIntegratedYet.txt

查看git-rev-list获取更多信息。

你可以尝试做git日志子集:

git log --oneline devel ^next