git 如何查看尚未推送的已提交文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3967261/
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
How to view the committed files you have not pushed yet?
提问by Usman Ali
For example I commit some files, the next day some more files, and so on. After some days I want to view all my committed files and view their difference with the remote repo. Note that I have not pushed anything. I just want to verify that if I push some thing then it will go to the remote repo as I expect.
例如,我提交了一些文件,第二天再提交一些文件,等等。几天后,我想查看我所有提交的文件并查看它们与远程存储库的区别。请注意,我没有推送任何内容。我只是想验证一下,如果我推送一些东西,那么它会按我的预期转到远程仓库。
采纳答案by tom
Here you'll find your answer:
在这里你会找到你的答案:
Using Git how do I find changes between local and remote
For the lazy:
对于懒人:
- Use "git log origin..HEAD"
- Use "git fetch" followed by "git log HEAD..origin". You can cherry-pick individual commits using the listed commit ids.
The above assumes, of course, that "origin" is the name of your remote tracking branch (which it is if you've used clone with default options).
- 使用“git log origin..HEAD”
- 使用“git fetch”后跟“git log HEAD..origin”。您可以使用列出的提交 ID 挑选单个提交。
当然,上面假设“origin”是您的远程跟踪分支的名称(如果您使用了带有默认选项的克隆,则为该名称)。
回答by bstpierre
Assuming you're on local branch master
, which is tracking origin/master
:
假设您在master
正在跟踪的本地分支上origin/master
:
git diff --stat origin/master..
回答by Noufal Ibrahim
The push
command has a -n
/--dry-run
option which will compute what needs to be pushed but not actually do it. Does that work for you?
该push
命令有一个-n
/--dry-run
选项,它将计算需要推送的内容,但实际上并不执行。那对你有用吗?
回答by Jason Capriotti
I'm not great with Git, but this is what I do. This does not necessarily compare with the remote repo, but you can modify the git diff
with the appropriate commit hash from the remote.
我不擅长 Git,但这就是我所做的。这不一定与远程存储库进行比较,但您可以使用远程git diff
的适当提交哈希修改。
Say you made one commit that you haven't pushed...
假设你做了一个你没有推送的提交......
First find the last two commits...
首先找到最后两个提交...
git log -2
This shows the last commit first, and descends from there...
这首先显示最后一次提交,然后从那里下降......
[jason:~/git/my_project] git log -2
commit ea7937edc8b10
Author: xyz
Date: Wed Jul 27 14:06:41 2016 -0500
Made a change in July
commit 52f9bf7956f0
Author: xyz
Date: Tue Jun 14 14:29:52 2016 -0500
Made a change in June
Now just use the two commit hashes (which I abbreviated) to run a diff:
现在只需使用两个提交哈希(我缩写)来运行差异:
git diff 52f9bf7956f0 ea7937edc8b10
回答by N 1.1
git diff HEAD origin/master
git diff HEAD origin/master
Where origin
is the remote repository and master
is the default branch where you will push. Also, do a git fetch
before the diff
so that you are not diffing against a stale origin/master.
origin
远程存储库在哪里,master
是您将推送到的默认分支。另外,在git fetch
之前做一个,diff
这样你就不会与陈旧的起源/主人不同。
P.S. I am also new to git, so in case the above is wrong, please rectify.
PS 我也是 git 新手,所以如果上面有错误,请纠正。