无法在终端中显示 Git 树

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1064361/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:39:34  来源:igfitidea点击:

Unable to show a Git tree in terminal

gitterminaltreeconsolerevision-history

提问by Léo Léopold Hertz ??

Killswitchcollective.com's old article, 30 June 2009, has the following inputs and outputs

Killswitchcollective.com 的旧文章,2009 年 6 月 30 日,有以下输入和输出

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

I am interested how you get the tree like-view of commits in your terminal without using Gitk or Gitx in OS/X.

我对如何在不使用 OS/X 中的 Gitk 或 Gitx 的情况下在终端中获得树状提交视图很感兴趣。

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

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

回答by VonC

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

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

git log --graph --oneline --all

is a good start.

是一个好的开始。

You may get some strange letters. They are ASCII codes for colors and structure. To solve this problem add the following to your .bashrc:

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

export LESS="-R"

such that you do not need use Tig's ASCII filter by

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

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

The article text-based graph from Git-readycontains other options:

来自 Git-ready的文章基于文本的图表包含其他选项:

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

git log graph

git日志图

Regarding the article you mention, I would go with Pod's answer: ad-hoc hand-made output.

关于您提到的文章,我会采用Pod 的答案:临时手工制作的输出。



Jakub Nar?bskimentions in the comments tig, a ncurses-based text-mode interface for git. See their releases.
It added a --graphoptionback in 2007.

全国房地产经纪人协会的Jakub?bski提到在评论TIG,一个基于ncurses的文本模式界面饭桶。查看他们的发布
它在 2007 年增加了一个--graph选项

回答by Marouane Gazanayi

A solution is to create an Alias in your .gitconfigand call it easily:

一种解决方案是在您的别名中创建一个别名.gitconfig并轻松调用它:

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

And when you call it next time, you'll use:

当您下次调用它时,您将使用:

git tree

To put it in your ~/.gitconfig without having to edit it, you can do:

要将其放入您的 ~/.gitconfig 而无需编辑它,您可以执行以下操作:

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

(If you don't use the --global it will put it in the .git/config of your current repo.)

(如果您不使用 --global 它将把它放在您当前存储库的 .git/config 中。)

回答by Sebastian Patten

git log --oneline --decorate --all --graph

A visual tree with branch names included.

包含分支名称的可视化树。

Use this to add it as an alias

使用此将其添加为别名

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

You call it with

你用

git tree

Git Tree

Git 树

回答by Mohsen

tig

tig

If you want a interactivetree, you can use tig. It can be installed by brewon OSX and apt-getin Linux.

如果你想要一个交互式树,你可以使用tig. 它可以brew在 OSX 和apt-getLinux上安装。

brew install tig
tig

This is what you get:

这是你得到的:

enter image description here

在此处输入图片说明

回答by JSON C11

Keeping your commands short will make them easier to remember:

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

git log --graph --oneline

回答by Saxophonist

I would suggest anyone to write down the full command

我建议任何人写下完整的命令

git log --all --decorate --oneline --graph

rather than create an alias.

而不是创建别名。

It's good to get the commands into your head, so you know it by heart i.e. do not depend on aliases when you change machines.

最好将命令记入您的脑海中,这样您就可以牢记在心,即在更换机器时不依赖于别名。