在 Git 日志中仅显示一个分支的历史记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4629358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show only history of one branch in a Git log
提问by Alex Recarey
I am using Git for my project and trying to follow best practice:
我在我的项目中使用 Git 并尝试遵循最佳实践:
- I work on a topic branch
- When ready, I merge the topic branchinto my devbranch using
git merge --squash
. This keeps my devbranch clean. - Whenever the devbranch is stable and the team decides it's time for a release, we merge the devbranch into the masterbranch, withoutusing squash, and tag that commit as a version release.
- 我在一个主题分支上工作
- 准备就绪后,我合并特性分支到我的dev的使用分支
git merge --squash
。这使我的开发分支保持干净。 - 每当dev分支稳定并且团队决定是时候发布时,我们将dev分支合并到master分支,而不使用 squash,并将该提交标记为版本发布。
This should keep our history, and using gitk, we can see where all of the commits come in. However, I want to be able to see onlythe commits applied to the masterbranch. I have tried:
这应该保留我们的历史记录,并且使用 gitk,我们可以看到所有提交的位置。但是,我希望能够只看到应用于master分支的提交。我试过了:
git log master
git show-branch
None of these show justthe history of the masterbranch. Is there a way to easily do this?
这些都不显示只是在历史的主分支。有没有办法轻松做到这一点?
采纳答案by James Kovacs
If I'm understanding you correctly, you want to see the merges back into master, but not the history of those merges. I believe that:
如果我理解正确,您希望看到合并回到 master,而不是这些合并的历史记录。我相信:
git log --merges
will give you what you want.
会给你你想要的。
UPDATE: Adding --first-parent should fix this from the sounds of it.
更新:添加 --first-parent 应该从它的声音中解决这个问题。
git log --merges --first-parent
--first-parent
Follow only the first parent commit upon seeing a merge commit.
This option can give a better overview when viewing the evolution of a particular topic branch, because merges into a topic branch tend to be only about adjusting to updated upstream from time to time, and this option allows you to ignore the individual commits brought in to your history by such a merge.
--first-parent
Follow only the first parent commit upon seeing a merge commit.
在查看特定主题分支的演变时,此选项可以提供更好的概览,因为合并到主题分支往往只是为了不时调整上游更新,而此选项允许您忽略引入的单个提交你的历史通过这样的合并。
回答by Kostas
Unfortunately, Git does not store branch information for a commit, and commits do not belong to a branch. Branches in Git are just "moving tags" in a course of commits and NOT a sequence of commits as one would expect.
不幸的是,Git 不存储提交的分支信息,并且提交不属于一个分支。Git 中的分支只是提交过程中的“移动标签”,而不是人们所期望的一系列提交。
So basically you cannot show commits that belong to a branch since there is no such concept in Git.
所以基本上你不能显示属于一个分支的提交,因为 Git 中没有这样的概念。
回答by user562374
Since Git does not store information about which branch is nascent from which other, there is no automatic way to guess which branch you could possibly want to be shown.
由于 Git 不存储关于哪个分支来自哪个分支的信息,因此无法自动猜测您可能希望显示哪个分支。
In that regard, --first-parent
will not ultimately help, especially since it is easy to have more than one master, for example. Consider:
在这方面,--first-parent
最终不会有帮助,尤其是因为例如很容易拥有多个大师。考虑:
wc1$ git clone git://shared.com/repo
wc1$ (hack code, git commit)
wc2$ git clone git://shared.com/repo
wc2$ (hack code, git commit, git push somewhere)
wc1$ git fetch origin; git merge origin/master; git push somewhere master;
(Feel free to take a random project and do this exercise.) Graph it. So you cannot meaningfully graph "just one branch", even if the commits were tagged with the name of the branch they were made on (because both are master).
(随意拿一个随机项目做这个练习。)把它画出来。所以你不能有意义地绘制“只有一个分支”,即使提交被标记为它们所在的分支的名称(因为两者都是主)。