简体   繁体   English

如何查看尚未推送的已提交文件?

[英]How to view the committed files you have not pushed yet?

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.我只是想验证一下,如果我推送一些东西,那么它会按我的预期转到远程仓库。

假设您在本地分支master ,它正在跟踪origin/master

git diff --stat origin/master..

Here you'll find your answer:在这里你会找到你的答案:

Using Git how do I find changes between local and remote 使用 Git 如何查找本地和远程之间的更改

For the lazy:对于懒人:

  1. Use "git log origin..HEAD"使用“git log origin..HEAD”
  2. Use "git fetch" followed by "git log HEAD..origin".使用“git fetch”后跟“git log HEAD..origin”。 You can cherry-pick individual commits using the listed commit ids.您可以使用列出的提交 ID 挑选单个提交。

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).当然,上面假设“origin”是您的远程跟踪分支的名称(如果您使用了带有默认选项的克隆)。

The push command has a -n / --dry-run option which will compute what needs to be pushed but not actually do it. push命令有一个-n / --dry-run选项,它将计算需要推送的内容,但实际上并不执行。 Does that work for you?那对你有用吗?

I'm not great with Git, but this is what I do.我不擅长 Git,但这就是我所做的。 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 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

git diff HEAD origin/master

Where origin is the remote repository and master is the default branch where you will push.其中origin是远程存储库, master是您将推送的默认分支。 Also, do a git fetch before the diff so that you are not diffing against a stale origin/master.此外,在diff之前执行git fetch以便您不会与陈旧的来源/主版本发生diff

PS I am also new to git, so in case the above is wrong, please rectify. PS 我也是 git 新手,所以如果上面有错误,请纠正。

The previous answers are all good, but they all show origin/master.前面的回答都很好,但是都显示了origin/master。 These days, following the best practices, I rarely work directly on a master branch, let alone from origin repo.如今,遵循最佳实践,我很少直接在 master 分支上工作,更不用说从 origin repo 了。

So if you are like me who work in a branch, here are tips:所以如果你像我一样在分行工作,这里有一些提示:

  1. Say you are already on a branch.假设你已经在一个分支上。 If not, git checkout that branch如果没有, git checkout 那个分支
  2. git log # to show a list of commit such as x08d46ffb1369e603c46ae96, You need only the latest commit which comes first. git log # 显示提交列表,例如 x08d46ffb1369e603c46ae96,您只需要最先出现的最新提交。
  3. git show --name-only x08d46ffb1369e603c46ae96 # to show the files commited git show --name-only x08d46ffb1369e603c46ae96 # 显示提交的文件
  4. git show x08d46ffb1369e603c46ae96 # show the detail diff of each changed file git show x08d46ffb1369e603c46ae96 # 显示每个更改文件的详细差异

Or more simply, just use HEAD:或者更简单地说,只需使用 HEAD:

  1. git show --name-only HEAD # to show a list of files committed git show --name-only HEAD # 显示提交的文件列表
  2. git show HEAD # to show the detail diff. git show HEAD # 显示细节差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 撤消所有本地提交但尚未推送的git文件 - undo all local committed yet not pushed files in git 如何在 Git 中显示所有已提交但尚未推送的内容? - How to show all committed-but-not-pushed-yet content in Git? 如何在尚未在GIT中提交的文件中获取修改后的行号? - How to get modified line numbers in files that have not been committed in GIT yet? 查找已提交但未推送的 git 文件 - find git files that are committed but not pushed 有没有办法将文件标记为已提交但未在 Windows 资源管理器上推送? - Is there a way to mark files as committed but not pushed on Windows Explorer? 查看我在Git和Mercurial中本地提交的文件 - View files that I have committed locally in Git and Mercurial 如何区分 Git 中需要拉取的文件和本地提交并准备推送的文件 - How to differentiate between files that need to be pulled in Git, and files that are committed locally and ready to be pushed Git恢复文件本地删除尚未提交 - Git restore files locally deleted not committed yet 如何撤消对Git中某些跟踪文件的已提交和推送的更改? - How do I undo my committed and pushed changes to some of the tracking files in Git? 如何取回提交给本地存储库的文件夹,而不是推送到 bitbucket 中的功能分支 - How to get back my files folder committed to local repo and not pushed to my feature branch in bitbucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM