查看未推送的 Git 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2016901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Viewing unpushed Git commits
提问by Josh Buhler
How can I view any local commits I've made, that haven't yet been pushed to the remote repository? Occasionally, git status
will print out that my branch is X commits ahead of origin/master
, but not always.
如何查看我所做的尚未推送到远程存储库的任何本地提交?有时,git status
会打印出我的分支是 X 之前的提交origin/master
,但并非总是如此。
Is this a bug with my install of Git, or am I missing something?
这是我安装 Git 的错误,还是我遗漏了什么?
回答by Peter B
git log origin/master..HEAD
You can also view the diff using the same syntax
您还可以使用相同的语法查看差异
git diff origin/master..HEAD
回答by cxreg
If you want to see all commits on all branches that aren't pushed yet, you might be looking for something like this:
如果您想查看尚未推送的所有分支上的所有提交,您可能正在寻找如下内容:
git log --branches --not --remotes
And if you only want to see the most recent commit on each branch, and the branch names, this:
如果您只想查看每个分支上的最新提交以及分支名称,请执行以下操作:
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
回答by Ben Lings
You can show all commits that you have locally but not upstream with
您可以显示您在本地但不在上游的所有提交
git log @{u}..
@{u}
or @{upstream}
means the upstream branch of the current branch (see git rev-parse --help
or git help revisions
for details).
@{u}
或@{upstream}
表示当前分支的上游分支(详见git rev-parse --help
或git help revisions
)。
回答by Christian Vielma
This worked for me:
这对我有用:
git cherry -v
As indicated at Git: See all unpushed commits or commits that are not in another branch.
回答by Greg Hewgill
回答by VonC
All the other answers talk about "upstream" (the branch you pull from).
But a local branchcan pushto a differentbranch than the one it pulls from.
所有其他答案都谈论“上游”(您从中拉出的分支)。
但是本地分支可以推送到与它拉取的分支不同的分支。
master
might not push to the remote tracking branch "origin/master
".
The upstreambranch for master
might be origin/master
, but it could push to the remote tracking branch origin/xxx
or even anotherUpstreamRepo/yyy
.
Those are set by branch.*.pushremote
for the current branch along with the global remote.pushDefault
value.
master
可能不会推送到远程跟踪分支“ origin/master
”。
的上游分支master
可能是origin/master
,但它可以推送到远程跟踪分支origin/xxx
甚至anotherUpstreamRepo/yyy
.
这些是由branch.*.pushremote
当前分支与global remote.pushDefault
值一起设置的。
It is thatremote-tracking branch which counts when seeking unpushed commits: the one that tracks the branch at the remote
where the local branchwould be pushed to.
The branch at the remote
can be, again, origin/xxx
or even anotherUpstreamRepo/yyy
.
这是远程跟踪分支,寻求unpushed提交时数:在一个轨道branch at the remote
在当地的分支机构将被推到。
该branch at the remote
可再次origin/xxx
或甚anotherUpstreamRepo/yyy
。
Git 2.5+ (Q2 2015) introduces a new shortcut for that: <branch>@{push}
Git 2.5+(2015 年第二季度)为此引入了一个新的快捷方式: <branch>@{push}
See commit 29bc885, commit 3dbe9db, commit adfe5d0, commit 48c5847, commit a1ad0eb, commit e291c75, commit 979cb24, commit 1ca41a1, commit 3a429d0, commit a9f9f8c, commit 8770e6f, commit da66b27, commit f052154, commit 9e3751d, commit ee2499f[all from 21 May 2015], and commit e41bf35[01 May 2015] by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
--in commit c4a8354, 05 Jun 2015)
见提交29bc885,提交3dbe9db,提交adfe5d0,提交48c5847,提交a1ad0eb,提交e291c75,提交979cb24,提交1ca41a1,提交3a429d0,提交a9f9f8c,提交8770e6f,提交da66b27,提交f052154,提交9e3751d,提交ee2499f[所有从5月21日2015],并由Jeff King ( )提交 e41bf35[2015 年 5 月 1 日] 。(由Junio C Hamano合并-- --peff
gitster
在提交 c4a8354 中,2015 年 6 月 5 日)
Commit adfe5d0explains:
提交 adfe5d0解释:
sha1_name
: implement@{push}
shorthandIn a triangular workflow, each branch may have two distinct points of interest: the
@{upstream}
that you normally pull from, and the destination that you normally push to. There isn't a shorthand for the latter, but it's useful to have.For instance, you may want to know which commits you haven't pushed yet:
sha1_name
: 实现@{push}
速记在三角工作流中,每个分支可能有两个不同的兴趣点:
@{upstream}
您通常从中拉出的点和通常推送到的目的地。后者没有简写,但它很有用。例如,您可能想知道您尚未推送哪些提交:
git log @{push}..
Or as a more complicated example, imagine that you normally pull changes from
origin/master
(which you set as your@{upstream}
), and push changes to your own personal fork (e.g., asmyfork/topic
).
You may push to your fork from multiple machines, requiring you to integrate the changes from the push destination, rather than upstream.
With this patch, you can just do:
或者作为一个更复杂的例子,假设您通常从
origin/master
(您设置为您的@{upstream}
)中提取更改,并将更改推送到您自己的个人分支(例如,作为myfork/topic
)。
你可以从多台机器推送到你的分支,需要你从推送目的地而不是上游集成更改。
使用此补丁,您可以执行以下操作:
git rebase @{push}
rather than typing out the full name.
而不是输入全名。
Commit 29bc885adds:
提交 29bc885添加:
for-each-ref
: accept "%(push)
" formatJust as we have "
%(upstream)
" to report the "@{upstream}
" for each ref, this patch adds "%(push)
" to match "@{push}
".
It supports the same tracking format modifiers as upstream (because you may want to know, for example, which branches have commits to push).
for-each-ref
: 接受 "%(push)
" 格式正如我们有“
%(upstream)
”来报告@{upstream}
每个参考的“ ”一样,这个补丁添加了“%(push)
”来匹配“@{push}
”。
它支持与上游相同的跟踪格式修饰符(因为您可能想知道,例如,哪些分支提交了 push)。
If you want to see how many commit your local branches are ahead/behindcompared to the branch you are pushing to:
如果您想查看与您要推送到的分支相比,您的本地分支领先/落后了多少提交:
git for-each-ref --format="%(refname:short) %(push:track)" refs/heads
回答by takeshin
Handy git alias for looking for unpushed commits in currentbranch:
方便的 git 别名,用于在当前分支中查找未推送的提交:
alias unpushed = !GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD) && git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline
What this basically does:
这基本上是做什么的:
git log origin/branch..branch
but also determines current branch name.
但也决定了当前的分支名称。
回答by Justin Ohms
You could try....
你可以试试....
gitk
I know it is not a pure command line option but if you have it installed and are on a GUI system it's a great way to see exactly what you are looking for plus a whole lot more.
我知道它不是一个纯粹的命令行选项,但是如果您安装了它并且在 GUI 系统上,这是一种很好的方式来准确地查看您正在寻找的内容以及更多内容。
(I'm actually kind of surprised no one mentioned it so far.)
(我实际上有点惊讶到目前为止没有人提到它。)
回答by Aurelien
git branch -v
will show, for each local branch, whether it's "ahead" or not.
git branch -v
将为每个本地分支显示它是否“领先”。
回答by Olaia
I had a commit done previously, not pushed to any branch, nor remote nor local. Just the commit. Nothing from other answers worked for me, but with:
我之前有一个提交,没有推送到任何分支,也没有远程或本地。只是提交。其他答案中没有任何对我有用,但是:
git reflog
There I found my commit.
在那里我找到了我的承诺。