如何仅在我的本地分支上使用“git log --graph --oneline --all”?

34

我想查看所有本地分支,但不包括远程跟踪引用,例如origin/master

这个命令会显示一个漂亮的图形,其中包括了所有本地和远程跟踪分支:

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

在这个命令中,我应该添加/删除哪个标志以仅显示本地分支?

4个回答

39

这将显示所有本地分支。

git log --graph --oneline --branches

git log --help

--branches[=<pattern>]
    Pretend as if all the refs in refs/heads are listed on the command line as <commit>.
    If <pattern> is given, limit branches to ones matching given shell glob.
    If pattern lacks ?, *, or [, /* at the end is implied.
所以--branches足矣。我喜欢添加--decorate并为整个命令设置一个简短的别名。

4
从Git 2.13版本开始,默认启用了--decorate选项。 - cambunctious

17

不确定您需要什么,但可以尝试以下命令:

git log --graph --oneline --branches --not --remotes=*

请注意这可能会过滤掉整个日志(例如,在您有一个最新的分支的情况下,因此您没有本地独有的内容)。请查阅 git help log 获取详细信息。

如果您只需要名称和最后一次提交,您可以简单地使用:

git branch -v

您可以混合使用它们来适应您的需求。

但是,我更喜欢使用 gitk --all,以下是示例输出:

enter image description here


@0x90 它显示了所有在本地分支中存在但不在任何远程仓库分支中的提交(有关详细信息,请参阅 git help log,在示例部分中您可以找到详细讨论)。 - rlegendi
1
尽管使用了--graph标志(尝试使用git 1.8.4),但似乎从未在图表中显示结果。 - pavon
我不知道我什么时候发布的,但我确定我在命令行中尝试过它 :-) 我想它大约是 ~1.8.2 左右,也许参数已经改变了。如果你弄清楚了,你知道你可以提出一个编辑建议吗? :-) 我现在手头没有 Git。 - rlegendi
注意:此命令不会显示本地分支是否跟踪上游分支,无论它们是否是最新的(即指向与上游分支相同的提交)! - waldyrious

3

正如其他人所提到的,问题并不是非常清晰明确,但是如果像我一样,你真正想做的是只对本地分支进行修饰,而保留远程分支的未修饰状态,那么可以使用以下调用的变体:

git log --graph --oneline --decorate-refs=refs/heads

其中关键参数为--decorate-refs=refs/heads

例如,这将导致从

(base) jdoubled@aig35 ~/packages/solarized $ git log --graph --decorate --pretty=oneline --abbrev-commit --all -n9
* 7ef17bf (HEAD -> topic_demoX) this demos going great
* b583669 (master) stupid empty commit for illustration only
* e40cd41 (origin/master, origin/HEAD) add tmux by @seebi!
*   ab3c564 Merge pull request #256 from sgerrand/add-credit-for-xfce4-terminal-port
|\
| * 4f90b03 Adds attribution for Xfce terminal port. Fixes #255.
* | 8a909d3 merge upstream xfce4-terminal changes
* | 04583c9 merge upstream gedit changes
* | f9e5943 add gedit back as a subtree
* | 53bfffc remove gedit submodule

目标:(请注意e40c上没有'origin/master')

(base) jdoubled@aig35 ~/packages/solarized $ git log --graph --decorate --pretty=oneline --abbrev-commit --all -n9 --decorate-refs=refs/heads
* 7ef17bf (topic_demoX) this demos going great
* b583669 (master) stupid empty commit for illustration only
* e40cd41 add tmux by @seebi!
*   ab3c564 Merge pull request #256 from sgerrand/add-credit-for-xfce4-terminal-port
|\
| * 4f90b03 Adds attribution for Xfce terminal port. Fixes #255.
* | 8a909d3 merge upstream xfce4-terminal changes
* | 04583c9 merge upstream gedit changes
* | f9e5943 add gedit back as a subtree
* | 53bfffc remove gedit submodule

应该向类似问题的这个答案致敬:https://stackoverflow.com/a/55730910/13938570 另外请注意,decorate-refs功能是在非常古老的1.8版本(我的系统管理员提供的版本)和2.28版本之间的某个版本中添加的。也许有人可以评论一下什么具体版本才可以使用。

这应该是被接受的答案。我猜这就是OP所问的,而且答案非常清晰,还有实际输出(这也是我的要求)。我还发现如果你只想隐藏特定的远程分支,--decorate-refs-exclude=refs/remotes/<remote_name> 也可以起作用。 - Shiva Prasad

1
你可以尝试这个:

git log --oneline --graph --decorate $(git branch | tr -d ' *' | awk '{ print "master~1.."$0 }')

这并不完美,但应该能够得到一个不错的输出结果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接