在 Git 中,列出未推送提交的分支名称
In Git, list names of branches with unpushed commits
给定一个有多个本地分支的项目,每个分支都跟踪一些远程分支,是否有一个命令可以列出所有未推送提交的分支? (也就是说,即使这些分支中的 none 个已签出。)
我不想看到提交本身,也不想看到最新的分支,我只想看看哪些分支领先于它们的远程。
我已经尝试了git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
,但它似乎没有显示我需要的东西。 运行 它在我当前的 repo 上没有输出,但是 运行 git status
在我当前的分支上显示 Your branch is ahead of 'origin/branchname' by 2 commits.
git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
和 git branch -v
都显示最新的分支以及需要推送的分支。但是,他们 do 都将我当前的分支显示为 [ahead 2]
。
我发现的其他命令,例如。 git log @{u}..
、git cherry -v
列出提交本身,而不是分支。
附带问题: 为什么 git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
的输出不包括 git branch -v
显示为前面的分支?前面的命令不就是看哪个 refs/heads
不对应一个已知的遥控器吗?那么列为 [ahead 2]
的分支机构不符合这个标准吗?
git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
这仍然是最精确的答案,您可以轻松地parse/grep获得所需的输出(例如删除最新的分支)
您可以在 bash 脚本中执行此操作,您将调用 git-xxx
(无扩展名),位于 $PATH
或 %PATH%
.[=24= 中的某处]
然后可以使用 git xxx
调用该脚本,并将使用 git bash.
这是可移植的,可以跨平台工作(意味着甚至在 Windows 上,其中 <Git For Windows>/usr/bin
包括 200 多个 linux 命令(grep
、sed
、awk
, xargs
, ...)
log
的 --no-walk
选项似乎比 --simplify-by-decoration
更能满足我的需求。我的完整命令是:
git log --branches --not --remotes --no-walk --decorate --oneline
...我已将其别名为 unpushed
。
还可以看到哪些分支还没有合并到master
git checkout master
然后
git branch --no-merged
虽然上面的答案非常有帮助并且显示了很多数据但是
对于其他来这里寻找解决方案以找到 ahead 的本地分支机构的人,即尚未被推送。可以通过执行得到确切的列表:
git branch -v | grep ahead
给定一个有多个本地分支的项目,每个分支都跟踪一些远程分支,是否有一个命令可以列出所有未推送提交的分支? (也就是说,即使这些分支中的 none 个已签出。)
我不想看到提交本身,也不想看到最新的分支,我只想看看哪些分支领先于它们的远程。
我已经尝试了git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
,但它似乎没有显示我需要的东西。 运行 它在我当前的 repo 上没有输出,但是 运行 git status
在我当前的分支上显示 Your branch is ahead of 'origin/branchname' by 2 commits.
git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
和 git branch -v
都显示最新的分支以及需要推送的分支。但是,他们 do 都将我当前的分支显示为 [ahead 2]
。
我发现的其他命令,例如。 git log @{u}..
、git cherry -v
列出提交本身,而不是分支。
附带问题: 为什么 git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
的输出不包括 git branch -v
显示为前面的分支?前面的命令不就是看哪个 refs/heads
不对应一个已知的遥控器吗?那么列为 [ahead 2]
的分支机构不符合这个标准吗?
git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
这仍然是最精确的答案,您可以轻松地parse/grep获得所需的输出(例如删除最新的分支)
您可以在 bash 脚本中执行此操作,您将调用 git-xxx
(无扩展名),位于 $PATH
或 %PATH%
.[=24= 中的某处]
然后可以使用 git xxx
调用该脚本,并将使用 git bash.
这是可移植的,可以跨平台工作(意味着甚至在 Windows 上,其中 <Git For Windows>/usr/bin
包括 200 多个 linux 命令(grep
、sed
、awk
, xargs
, ...)
log
的 --no-walk
选项似乎比 --simplify-by-decoration
更能满足我的需求。我的完整命令是:
git log --branches --not --remotes --no-walk --decorate --oneline
...我已将其别名为 unpushed
。
还可以看到哪些分支还没有合并到master
git checkout master
然后
git branch --no-merged
虽然上面的答案非常有帮助并且显示了很多数据但是 对于其他来这里寻找解决方案以找到 ahead 的本地分支机构的人,即尚未被推送。可以通过执行得到确切的列表:
git branch -v | grep ahead