Git 仓库可视化

在本文中,我们将了解如何获得仓库的可视化。我们将使用 git log 命令查看仓库的拓扑结构。

可视化 Git 仓库

大多数使用 Git 的开发人员将大部分时间花在 bash 终端上。一个简单的 git log 命令将列出你的所有提交。

但是,很难为你的仓库开发一个心智模型。其他人可能会发现很难理解你的工作流程。

幸运的是,你可以使用方法来可视化你的仓库,我们将在稍后介绍。

在下面的示例中,我们使用 git log --oneline --all 查看仓库的历史记录。

pc@JOHN MINGW64 ~/Git (main)
$ git log --oneline --all
e923721 (refs/stash) WIP on main: 78129a6 Revert "$git status"
032ee0a index on main: 78129a6 Revert "git status"
78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "$git status"
195e5c3 git status
7b19db4 first commit
b2f7710 (origin/main) Initial commit

以上只是一个简单的平面视图。你可以添加 --graph 参数以获得更好的视图。

然后你的命令应该是 git log --oneline --all --graph

例子:

pc@JOHN MINGW64 ~/Git (main)
$ git log --oneline --all --graph
*   e923721 (refs/stash) WIP on main: 78129a6 Revert "git status"
|\
| * 032ee0a index on main: 78129a6 Revert "git status"
|/
* 78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "git status"
* 195e5c3 $git status
* 7b19db4 first commit
* b2f7710 (origin/main) Initial commit

这看起来更好,但我们可以进一步识别分支和标记标签。

我们在以下上下文中使用 --decorate 参数。

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

你还可以添加 --color 参数以使布局在以下上下文中更好。

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

每当你想可视化你的仓库时,键入它是一个相当长的命令。通过为你的命令分配别名来使自己更容易,如下所示。

在下面的示例中,我们将为 git log --oneline --all --graph --decorate --color 命令赋予别名 glt

pc@JOHN MINGW64 ~/Git (main)
$ alias glt='git log --oneline --decorate --graph --all'

让我们使用别名运行命令。

pc@JOHN MINGW64 ~/Git (main)
$ alias glt
alias glt='git log --oneline --decorate --graph --all'
pc@JOHN MINGW64 ~/Git (main)
$ glt
*   e923721 (refs/stash) WIP on main: 78129a6 Revert "$git status"
|\
| * 032ee0a index on main: 78129a6 Revert "$git status"
|/
* 78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "$git status"
* 195e5c3 $git status
* 7b19db4 first commit
* b2f7710 (origin/main) Initial commit