Output of git branch in tree like fashion

前端 未结 6 869
野的像风
野的像风 2020-12-04 04:34

Right now, when I type \"git branch\"

it lists my branches in an arbitrary order.

What I would prefer would be if \"git branch\" listed my output in a tree l

6条回答
  •  忘掉有多难
    2020-12-04 05:07

    The answer below uses git log:

    I mentioned a similar approach in 2009 with "Unable to show a Git tree in terminal":

    git log --graph --pretty=oneline --abbrev-commit
    

    But the full one I have been using is in "How to display the tag name and branch name using git log --graph" (2011):

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

    Original answer (2010)

    git show-branch --list comes close of what you are looking for (with the topo order)

    --topo-order
    

    By default, the branches and their commits are shown in reverse chronological order.
    This option makes them appear in topological order (i.e., descendant commits are shown before their parents).

    But the tool git wtf can help too. Example:

    $ git wtf
    Local branch: master
    [ ] NOT in sync with remote (needs push)
        - Add before-search hook, for shortcuts for custom search queries. [4430d1b] (edwardzyang@...; 7 days ago)
    Remote branch: origin/master (git@gitorious.org:sup/mainline.git)
    [x] in sync with local
    
    Feature branches:
    { } origin/release-0.8.1 is NOT merged in (1 commit ahead)
        - bump to 0.8.1 [dab43fb] (wmorgan-sup@...; 2 days ago)
    [ ] labels-before-subj is NOT merged in (1 commit ahead)
        - put labels before subject in thread index view [790b64d] (marka@...; 4 weeks ago)
    {x} origin/enclosed-message-display-tweaks merged in
    (x) experiment merged in (only locally)
    
    NOTE: working directory contains modified files
    

    git-wtf shows you:

    • How your branch relates to the remote repo, if it's a tracking branch.
    • How your branch relates to non-feature ("version") branches, if it's a feature branch.
    • How your branch relates to the feature branches, if it's a version branch

提交回复
热议问题