我如何才能看到我将要使用 git 推送的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3636914/
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 can I see what I am about to push with git?
提问by cmcculloh
Is there a way to see what would be pushed if I did a git push
command?
有没有办法查看如果我git push
执行命令会被推送什么?
What I'm picturing is something like the "Files Changed" tab of Github's "pull request" feature. When I issue a pull request, I can look and see what will be pulled in if they accept my pull request:
我所描绘的是类似于 Github 的“拉取请求”功能的“文件更改”选项卡。当我发出拉取请求时,我可以查看如果他们接受我的拉取请求,将会拉取什么内容:
Command line is OK, but I'd prefer some sort of GUI (like the screenshot above).
命令行没问题,但我更喜欢某种 GUI(如上面的屏幕截图)。
回答by Ionu? G. Stan
For a list of files to be pushed, run:
要获取要推送的文件列表,请运行:
git diff --stat --cached [remote/branch]
example:
例子:
git diff --stat --cached origin/master
For the code diff of the files to be pushed, run:
对于要推送的文件的代码差异,运行:
git diff [remote repo/branch]
To see full file paths of the files that will change, run:
要查看将更改的文件的完整文件路径,请运行:
git diff --numstat [remote repo/branch]
If you want to see these diffs in a GUI, you will need to configure git for that. See How do I view 'git diff' output with a visual diff program?.
如果您想在 GUI 中查看这些差异,则需要为此配置 git。请参阅如何使用可视化差异程序查看“git diff”输出?.
回答by Brian Gianforcaro
There is always dry-run:
总是有空运行:
git push --dry-run
It will do everything except for the actually sending of the data.
除了实际发送数据之外,它会做所有事情。
If you want a more graphical view you have a bunch of options.
如果你想要一个更图形化的视图,你有很多选择。
Tigand the gitk script that come with git both display the current branch of your local copy and the branch of the remote or origin.
Tig和 git 附带的 gitk 脚本都显示本地副本的当前分支和远程或源的分支。
So any commits you make that are after the origin are the commits that will be pushed.
因此,您在原点之后所做的任何提交都是将被推送的提交。
Open gitk from shell while in the branch you want to push by typing gitk&
, then to see the difference between what is on the remote and what you are about to push to the remote, select your local unpushed commit and right-click on the remote and choose "Diff this -> selected":
在要推送的分支中打开 gitk,通过键入gitk&
,然后查看远程上的内容与将要推送到远程的内容之间的区别,选择本地未推送的提交并右键单击远程并选择“Diff this -> selected”:
回答by Alex Nolasco
To simply list the commits waiting to be pushed:(this is the one you will remember)
如果只列出等待推提交:(这是你会记得一个)
git cherry -v
Show the commit subjects next to the SHA1s.
在 SHA1 旁边显示提交主题。
回答by Scott Chacon
You probably want to run git difftool origin/master...
. that should show the unified diff of what is on your current branch that is not on the origin/master branch yet and display it in the graphical diff tool of your choice. To be most up-to-date, run git fetch
first.
您可能想要运行git difftool origin/master...
. 这应该显示当前分支上尚未在 origin/master 分支上的内容的统一差异,并将其显示在您选择的图形差异工具中。要获得最新信息,git fetch
请先运行。
回答by user1921207
One way to compare your local version before pushing it on the remote repo (kind of push in dry-run):
在将本地版本推送到远程存储库之前比较本地版本的一种方法(干运行的一种推送):
Use TortoiseGit:
Right click on the root folder project > TortoiseGit > Diff with previous version >
for Version 2 choose refs/remotes/origin/master
使用 TortoiseGit:
右键单击根文件夹项目 > TortoiseGit > Diff with previous version >
对于 Version 2 选择refs/remotes/origin/master
回答by Ed Avis
Try git diff origin/master..master
(assuming that origin/master
is your upstream). Unlike git push --dry-run
, this still works even if you don't have write permission to the upstream.
尝试git diff origin/master..master
(假设这origin/master
是您的上游)。与 不同git push --dry-run
,即使您没有对上游的写权限,这仍然有效。
回答by fuz
Use git gui
, there you can see a list of what changed in your actual commit. You can also use gitk
wich provides an easy interface for reflogs. Just compare between remotes/...
and master
to see, what will be pushed. It provides an interface similar to your screenshot.
使用git gui
,您可以在那里看到实际提交中更改的列表。您还可以使用gitk
wich 为 reflogs 提供一个简单的界面。只是比较remotes/...
和master
看看,什么会被推。它提供了一个类似于您的屏幕截图的界面。
Both programs are included in git.
这两个程序都包含在 git 中。
回答by ccpizza
To see which files are changed andview the actual code changes compared to the master
branch you could use:
要查看更改了哪些文件并查看与master
您可以使用的分支相比的实际代码更改:
git diff --stat --patch origin master
NOTE: If you happen to use any of the Intellij IDEs then you can right-click your top-level project, select Git> Compare with branch> and pick the origin you want e.g. origin/master
. In the file tree that will appear you can double-click the files to see a visual diff. Unlike the command-line option above you can edit your local versions from the diff window.
注意:如果您碰巧使用任何 Intellij IDE,那么您可以右键单击您的顶级项目,选择Git>与分支比较> 并选择您想要的来源,例如origin/master
. 在将出现的文件树中,您可以双击文件以查看视觉差异。与上面的命令行选项不同,您可以从差异窗口编辑本地版本。
回答by DavidS
You can list the commits by:
您可以通过以下方式列出提交:
git cherry -v
And then compare with the following command where the number of ^ equals to the number of commits (in the example its 2 commits):
然后与以下命令进行比较,其中 ^ 的数量等于提交的数量(在示例中为 2 次提交):
git diff HEAD^^
回答by kakubei
If you are using Mac OS X, I would recommend you get Tower, it's a wonderful program that has made dealing with Git a pleasure for me. I now longer have to remember terminal commands and it offers a great GUI to view, track and solve differences in files.
如果您使用的是 Mac OS X,我建议您使用 Tower,它是一个很棒的程序,它让我很高兴处理 Git。我现在不再需要记住终端命令,它提供了一个很棒的 GUI 来查看、跟踪和解决文件中的差异。
And no, I'm not affiliated with them, I just use their software and really like it.
不,我不隶属于他们,我只是使用他们的软件并且非常喜欢它。