如何使用分支名称显示git日志

时间:2023-01-15 23:44:13

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 w / --decorate和--source选项。但仍然无法获得提交2f3cb60和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日志?

1 个解决方案

#1


23  

$ 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>.
  • 您可以通过git branch查看哪些分支包含提交--contains
  • If you just need some kind of symbolic name to track down a commit, use git name-rev <ref>.
  • 如果您只需要某种符号名称来跟踪提交,请使用git name-rev
  • If you need a shell-scriptable ("plumbing") list of all branches containing a commit, try this:

    如果您需要包含提交的所有分支的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:查找提交来自哪个分支

#1


23  

$ 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>.
  • 您可以通过git branch查看哪些分支包含提交--contains
  • If you just need some kind of symbolic name to track down a commit, use git name-rev <ref>.
  • 如果您只需要某种符号名称来跟踪提交,请使用git name-rev
  • If you need a shell-scriptable ("plumbing") list of all branches containing a commit, try this:

    如果您需要包含提交的所有分支的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:查找提交来自哪个分支