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

g6ll5ycj  于 2022-11-20  发布在  Git
关注(0)|答案(4)|浏览(138)

我 想 查看 所有 本地 分支 , 但 不 想 查看 远程 跟踪 引用 , 如 origin/master
这个 命令 显示 了 一 个 很 好 的 图表 , 上面 装饰 了 我 所有 的 本地 和 远程 跟踪 分支 :

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

中 的 每 一 个
我 应该 在 此 命令 中 添加/删除 什么 标志 才 能 只 显示 本地 分支 ?

ugmeyewa

ugmeyewa1#

这将显示所有本地分支。

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,并给予整个命令一个简短的别名。

cczfrluj

cczfrluj2#

我不知道你需要什么,但这样的东西怎么样:
git log --graph --oneline --branches --not --remotes=*

  • 请注意,它可能会过滤掉整个日志 *(例如,当您有一个最新的分支,所以没有您只有本地的情况下)。请咨询git help log了解详细信息。

如果你只需要名字和上次提交,你可以简单地用途:
git branch -v
也许你可以混合这些来满足你的需要。
但我的首选是gitk --all,下面是一个示例输出:

rslzwgfq

rslzwgfq3#

正如其他人所提到的,它不完全清楚的问题是问什么,但如果像我一样,你真正想做的是 * 装饰 * 只你的本地分支,留下可能是远程分支未装饰,你可以使用以下调用的变化:

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

至(注意e40 c上缺少“原始/主”)

(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特性是在git的1.8(我的系统管理员提供的版本)和2.28版本之间添加的。也许有人可以评论一下这个特性是在哪个版本中实现的。

kqlmhetl

kqlmhetl4#

您可以尝试以下操作:

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

它并不完美,但应该会给你一个体面的输出。

相关问题