如何显示带有分支名称的 git log
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13954376/
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
How to show git log with branch name
提问by Robber Pen
I try git log
w/ --decorate
and --source
options. But still can not get the branch name of commit 2f3cb60
and d7e7776
, Why?
我尝试git log
带--decorate
和--source
选项。但是还是拿不到commit2f3cb60
和 的分支名 d7e7776
,为什么?
#git log 2f3cb60 --graph --decorate --source --all --oneline
...
* | | | 1920ad5 refs/heads/gpio support gpio lib
| |/ /
|/| |
* | | 2f3cb60 2f3cb60 fix
* | | d7e7776 2f3cb60 fix
| |/
|/|
* | aa4dcfb refs/remotes/origin/httpd support
* | cfc839d refs/remotes/origin/httpd add folder
How do I show git log with branch name?
如何显示带有分支名称的 git log?
回答by Jeff Bowman
$ git log --graph --decorate --oneline
* 1f3e836 (HEAD, origin/v2, v2) Change scripts to new format.
* 34d458f (origin/master, master) Merge branch 'new-shell'
|\
| * 995ece7 (origin/new-shell) Fix index.html and add script pushing.
| * fe0615f New shell hello-world.
|/
* fe1b1c0 Progress.
...
git log --graph --decorate --oneline
should show you names of the commits that have names. Not every commit is associated with a branch name.
git log --graph --decorate --oneline
应该向您显示具有名称的提交的名称。并非每个提交都与分支名称相关联。
Remember, a branch name is just a pointer to a particular commit. Each commit has a parent, so one commit may be a part of the history of a dozen separate branches.
请记住,分支名称只是指向特定提交的指针。每个提交都有一个父提交,因此一个提交可能是十几个独立分支历史记录的一部分。
- You can see which branches contain a commit via
git branch --contains <ref>
. - If you just need some kind of symbolic name to track down a commit, use
git name-rev <ref>
. If you need a shell-scriptable ("plumbing") list of all branches containing a commit, try this:
commit=$(git rev-parse <ref>) # expands hash if needed for branch in $(git for-each-ref --format "%(refname)" refs/heads); do if git rev-list "$branch" | fgrep -q "$commit"; then echo "$branch" fi done
- 您可以通过
git branch --contains <ref>
. - 如果您只需要某种符号名称来跟踪提交,请使用
git name-rev <ref>
. 如果您需要包含提交的所有分支的 shell-scriptable ( "plumbing") 列表,请尝试以下操作:
commit=$(git rev-parse <ref>) # expands hash if needed for branch in $(git for-each-ref --format "%(refname)" refs/heads); do if git rev-list "$branch" | fgrep -q "$commit"; then echo "$branch" fi done
See also: SO: Finding what branch a commit came from
另请参阅:SO:查找提交来自哪个分支