Showing Git branch structure

2020-02-02 06:26发布

Is there a way to show only the branch structure in Git? There are a number of tools that show the commits graphically, but in my case the list is so long that it's impossible to see the structure. I guess git-log could be the answer, but I can't find any switches that only show the branching commits. This along with "--graph --branches --oneline --all" could do the trick.

EDIT: I'm looking for a way to do this in Ubuntu.

6条回答
Summer. ? 凉城
2楼-- · 2020-02-02 06:43

Basic solution is:

git log --graph --all

If you want to get more fancy:

git log --graph --all --pretty=format:"%Cblue%h%Creset [%Cgreen%ar%Creset] %s%C(yellow)%d%Creset"
查看更多
Melony?
3楼-- · 2020-02-02 06:46

To get more information on how a particular branch relates to other branches in your repository and remotes, you can use git wtf which is an add on script by William Morgan: http://git-wt-commit.rubyforge.org/

It produces summary information like:

$ git wtf
Local branch: master
[x] in sync with remote
Remote branch: origin/master (git@gitorious.org:willgit/mainline.git)
[x] in sync with local

Feature branches:
{ } origin/experimental is NOT merged in (1 commit ahead)
    - some tweaks i'm playing around with [80e5da1]
{ } origin/dont-assume-origin is NOT merged in (1 commit ahead)
    - guess primary remote repo from git config instead of assuming "origin" [23c96f1]

(example taken from the above URL).

查看更多
啃猪蹄的小仙女
4楼-- · 2020-02-02 06:52

Perhaps what you want is --simplify-by-decoration option, see git log documentation:

--simplify-by-decoration

     Commits that are referred by some branch or tag are selected.

So it would be

git log --graph --simplify-by-decoration --all

or following VonC answer

git log --graph --simplify-by-decoration \
   --pretty=format:'%Cred%h%Creset-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
   --abbrev-commit --date=relative
查看更多
ら.Afraid
5楼-- · 2020-02-02 06:55

I am not sure about what you mean by "branch structure".
git log can help visualize the branches made through commits (See this blog post):

[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

alt text

But if you only wants the different HEAD branches, you could try something along the lines of:

heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"

(using the column command, and here only for commits since the last origin/master commit)

Note: Jakub Narębski recommands adding the option --simplify-by-decoration, see his answer.

查看更多
太酷不给撩
6楼-- · 2020-02-02 07:00

Maybe I'm missing something, but nobody seems to have mentioned gitk --all yet.

查看更多
别忘想泡老子
7楼-- · 2020-02-02 07:02

gitx if you are on a macOS

smartgit for macOS or Windows (but i have not used it)

git-gui to use the native git gui (cross-platform)

查看更多
登录 后发表回答