我很好奇是否有办法在命令行上显示分支层次结构?例如,如果我使用git branch,而不是看到这样的输出:
* master
joes_work
refactoring
experiment
Run Code Online (Sandbox Code Playgroud)
你看到这样的输出:
* master
joes_work
refactoring
experiment
Run Code Online (Sandbox Code Playgroud)
这样就很容易看出哪个分支是一个特定的分支.即使没有输出树结构的特定命令,是否有一个命令可以输出哪个分支来自哪个分支的信息?我可以使用perl脚本来格式化输出.
ctc*_*rry 101
sehe的解决方案看起来很棒,这是另一个似乎包含类似信息,格式不同,它使用git log,所以它也包含提交信息(忽略分支名称,我搞砸了!):
git log --all --graph --decorate --oneline --simplify-by-decoration
* ae038ad (HEAD, branch2-1) add content to tmp1
| * f5a0029 (branch2-1-1) Add another
|/
* 3e56666 (branch1) Second wave of commits
| * 6c9af2a (branch1-2) add thing
|/
* bfcf30a (master) commit 1
Run Code Online (Sandbox Code Playgroud)
seh*_*ehe 27
尝试
git show-branch
git show-branch --all
Run Code Online (Sandbox Code Playgroud)
示例输出:
bash$ git show-branch --all
! [branchA] commitA only in branchA
* [branchB] commitB
! [branchC] commitC only in branchC
---------------------
+ [branchA] commitA only in branchA
* [branchB] commitB
+ [branchC] commitC only in branchC
*+ [branchC~1] commitB-1 also in branchC
*+ [branchC~2] commitB-2 also in branchC
+++ [branchC~3] common ancestor
+++ [branchC~4] more common ancestors
Run Code Online (Sandbox Code Playgroud)
Car*_*lex 14
我想完成@ctcherry的答案。
我喜欢在还能看到执行提交和日期的用户的情况下,因此使用以下行:
git log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Run Code Online (Sandbox Code Playgroud)
但是,这是一条很长的线,很难记住,因此可以使用别名。您只需要在终端中使用它:
git config --global alias.lg "HERE GOES MY BIG LOG COMMAND LINE"
总结一下,将以下行复制并粘贴到您的终端上:
git config --global alias.lg "log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Run Code Online (Sandbox Code Playgroud)
然后,您将仅需使用它git lg来获取日志历史记录树。
从git的角度来看,这不是分支机构的工作方式.如果我做一些提交分支a,b从它创建分支,在那里工作,然后做其他工作a:
A -- B -- D <-- a
\
\
C <-- b
Run Code Online (Sandbox Code Playgroud)
如果你以相反的方式做到这一点,这是无法区分的:
A -- B -- C <-- b
\
\
D <-- a
Run Code Online (Sandbox Code Playgroud)
我可以想到找出某个分支来自哪个分支的唯一方法是reflog,但这是不可靠的(超过90天的条目通常被删除).