Show only history of one branch in a Git log

允我心安 提交于 2019-11-30 05:58:08

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:

git log --merges

will give you what you want.

UPDATE: Adding --first-parent should fix this from the sounds of it.

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.

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.

So basically you cannot show commits that belong to a branch since there is no such concept in Git.

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.

In that regard, --first-parent will not ultimately help, especially since it is easy to have more than one master, for example. Consider:

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!