如何在 git 中查看传入的提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1331385/
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 incoming commits in git?
提问by Benjamin Pollack
Possible Duplicate:
Using Git how do I find modified files between local and remote
How can I see incoming commits in git? Or even better, see what I just git fetch
/git pull
ed?
如何在 git 中查看传入的提交?或者甚至更好,看看我刚刚git fetch
/ git pull
ed 是什么?
Edit:To clarify the question: someone tells me that, to get some fixes, I should pull from their repository. My goal is to see what their changes are beforeI accept them. git pull
automatically merges, which is not what I want. git fetch
will grab them without merging, but I'm unsure how to view what exactly I just pulled in. The reason for the original phrasing is that I normally use Mercurial, where the command would be hg incoming <repo name here>
—a command for which git seems to lack an analog.
编辑:澄清这个问题:有人告诉我,要获得一些修复,我应该从他们的存储库中提取。我的目标是在我接受它们之前查看它们的变化。 git pull
自动合并,这不是我想要的。 git fetch
将在不合并的情况下抓取它们,但我不确定如何查看我刚刚拉入的内容。原始措辞的原因是我通常使用 Mercurial,命令所在的位置hg incoming <repo name here>
- git 似乎缺少模拟的命令.
回答by Dustin
incoming
isn't quite a direct mapping in git because you can (and I often do) have multiple repos you're pulling from, and each repo has multiple branches.
incoming
不是 git 中的直接映射,因为您可以(而且我经常这样做)有多个要从中提取的存储库,并且每个存储库都有多个分支。
If there were an equivalent of hg's incoming command, it'd probably be this:
如果有一个等效于 hg 的传入命令,它可能是这样的:
git fetch && git log ..origin/master
That is, "go grab all of the stuff from the upstream, and then compare my current branch against the upstream master branch."
也就是说,“去从上游获取所有的东西,然后将我当前的分支与上游主分支进行比较。”
Similarly, outgoing would be this:
同样,传出将是这样的:
git fetch && git log origin/master..
In practice, I just type those manually (even though I created an alias for one of them) because it's easy to have lots of local branches tracking and being tracked by lots of remote branches and have no trouble keeping it together.
在实践中,我只是手动输入它们(即使我为其中一个创建了别名),因为很容易让大量本地分支跟踪并被大量远程分支跟踪,并且将它们保持在一起没有问题。
回答by Greg Hewgill
You may also be interested in git whatchanged
which gives a good overview of changes that have been made in some range of commits.
您可能还对git whatchanged
which 对在某些提交范围内所做的更改进行了很好的概述感兴趣。
If you want to review what you're about to pull, do a git fetch
first, which only updates local tracking branches for the remote repository (and not any of yourbranches), and then use any command that shows you the new commits that you're about to pull. For example:
如果您想查看您将要拉取的内容,git fetch
请先执行一次,它只会更新远程存储库的本地跟踪分支(而不是您的任何分支),然后使用任何显示您的新提交的命令再要拉。例如:
git whatchanged ..origin
This is shorthand for showing the commits between "the common ancestor of wherever I am now and origin" through "origin".
这是通过“起源”显示“我现在所在之处的共同祖先和起源”之间的提交的简写。
回答by Netzpirat
You may want to examine the difference between two repositories. Assumed you have a local branch 'master' and a remote-tracking branch 'origin/master', where other people commit their code, you can get different stats about the differences of the two branches:
您可能想要检查两个存储库之间的差异。假设你有一个本地分支 'master' 和一个远程跟踪分支 'origin/master',其他人在那里提交他们的代码,你可以得到关于两个分支差异的不同统计信息:
git diff --summary master origin/master
git diff --stat master origin/master
git diff --numstat master origin/master
git diff --dirstat master origin/master
git diff --shortstat master origin/master
git diff --name-only master origin/master
git diff master origin/master
回答by Sitaram
When someone tells you to pull, they will give you the repo URL and a branch (default being master
).
当有人告诉你拉,他们会给你 repo URL 和一个分支(默认是master
)。
I'd just do
我只想做
git fetch URL branch
followed by one (in decreasing order of preference):
后跟一个(按优先顺序递减):
# note 3 dots in next 3 commands
gitk HEAD...FETCH_HEAD
# shows all commits on both sides since the "fork" point
gitk --cherry-pick HEAD...FETCH_HEAD
# as above but skips identical patches so you really see the differences
git log --graph --boundary --left-right --cherry-pick --decorate HEAD...FETCH_HEAD
# I have a nice alias for this; it's the text mode eqvt of the above
I also use "tig
" sometimes, but this specific usecase (seeing bothsides) is not well served by tig
.
我也用“ tig
”有时,但这个特定用例(看到这两个双方)没有很好地提供服务tig
。
However, if you bring it down to two dots (which may match your actual question more closely, though I still prefer the 3 dot versions), you can do
但是,如果您将其简化为两个点(这可能更接近您的实际问题,但我仍然更喜欢 3 点版本),您可以这样做
tig HEAD..FETCH_HEAD
Here are the aliases for convenience:
为方便起见,以下是别名:
incoming = !sh -c 'git fetch && git log --graph --boundary --left-right --cherry-pick --decorate HEAD..FETCH_HEAD'
outgoing = !sh -c 'git fetch && git log --graph --boundary --left-right --cherry-pick --decorate FETCH_HEAD..HEAD'
回答by JP Silvashy
There is no such thing as "incoming commits" users commit locally and push them. I would open up gitx or gitk(that comes with git) and check out what the repos looks like... I think that will give you a clear view.
没有“传入提交”这样的东西,用户在本地提交并推送它们。我会打开 gitx 或 gitk(与 git 一起提供)并查看 repos 的样子......我认为这会给你一个清晰的视图。
use: gitk --all
to see.
用:gitk --all
看。