可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
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 before I 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.
回答1:
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.
If there were an equivalent of hg's incoming command, it'd probably be this:
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.
回答2:
You may also be interested in git whatchanged
which gives a good overview of changes that have been made in some range of commits.
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 your branches), and then use any command that shows you the new commits that you're about to pull. For example:
git whatchanged ..origin
This is shorthand for showing the commits between "the common ancestor of wherever I am now and origin" through "origin".
回答3:
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:
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
回答4:
When someone tells you to pull, they will give you the repo URL and a branch (default being 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 both sides) is not well served by 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
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'
回答5:
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.
use: gitk --all
to see.
回答6:
Have a look at this post. It shows you the usage of a new feature which was introduced in git version 1.7 Using Git how do I find changes between local and remote