首页 文章

无法在终端中显示Git树

提问于
浏览
345

Killswitchcollective.com's old article, 30 June 2009,具有以下输入和输出

git co master
git merge [your_branch]
git push

upstream    A-B-C-D-E            A-B-C-D-E-F-G
                 \        ---->               \
your branch       C-D-E                        G

我感兴趣的是如何在终端中获得提交树的视图,而不使用OS / X中的Gitk或Gitx .

How can you get the tree-like view of commits in terminal?

5 回答

  • 619

    如何在终端获得树状的提交视图?

    git log --graph --oneline --all
    

    是一个好的开始 .

    你可能会收到一些奇怪的信件 . 它们是颜色和结构的ASCII代码 . 要解决此问题,请将以下内容添加到 .bashrc

    export LESS="-R"
    

    这样你就不需要使用Tig的ASCII过滤器了

    git log --graph --pretty=oneline --abbrev-commit | tig   // Masi needed this
    

    文章text-based graph from Git-ready包含其他选项:

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

    git log graph

    关于你提到的文章,我会选择Pod's answer:ad-hoc手工制作的输出 .


    Jakub Narębski 在评论 tig 中提到,这是一个基于ncurses的git文本模式界面 . 见their releases .
    它在2007年增加了a --graph option .

  • 260

    解决方案是在 .gitconfig 中创建一个Alias并轻松调用它:

    [alias]
        tree = log --graph --decorate --pretty=oneline --abbrev-commit
    

    当你下次打电话时,你将使用:

    git tree
    

    要将它放在〜/ .gitconfig中而不必编辑它,你可以这样做:

    git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"
    

    (如果你不使用--global,它会把它放在你当前仓库的.git / config中 . )

  • 3
    git log --oneline --decorate --all --graph
    

    包含分支名称的可视树 .

    使用此选项将其添加为别名

    git config --global alias.tree "log --oneline --decorate --all --graph"
    

    你打电话给它

    git tree
    

    Git Tree

  • 104

    tig

    如果你想要一个 interactive 树,你可以使用tig . 它可以在OSX上由 brew 安装,在Linux中由 apt-get 安装 .

    brew install tig
    tig
    

    这就是你得到的:

    enter image description here

  • 47

    保持命令简短将使它们更容易记住:

    git log --graph --oneline
    

相关问题