views:

3060

answers:

2

Is it even possible?

Basically, there's a remote repository from which I pull using just:

git pull

Now, I'd like to preview what this pull would change (a diff) without touching anything on my side. The reason is that thing I'm pulling might not be "good" and I want someone else to fix it before making my repository "dirty".

+3  A: 

I think git fetch is what your looking for.

It will pull the changes and objects without committing them to your local repo's index.

They can be merged later with git merge.

Man Page

Edit: Further Explination

Straight from the Git- SVN Crash Course link

Now, how do you get any new changes from a remote repository? You fetch them:

git fetch http://host.xz/path/to/repo.git/

At this point they are in your repository and you can examine them using:

git log origin

You can also diff the changes. You can also use git log HEAD..origin to see just the changes you don't have in your branch. Then if would like to merge them - just do:

git merge origin

Note that if you don't specify a branch to fetch, it will conveniently default to the tracking remote.

Reading the man page is honestly going to give you the best understanding of options and how to use it.

I'm just trying to do this by examples and memory, I don't currently have a box to test out on. You should look at:

git log -p //log with diff

A fetch can be undone with git reset --hard (link) , however all uncommitted changes in your tree will be lost as well as the changes you've fetched.

Brian Gianforcaro
If you explain two things, that might be good: 1. how do I undo git-fetch? 2. How do I see the diff?
Milan Babuškov
1) undoing git-fetch? 2) git diff HEAD..origin
Christian Vest Hansen
The diff is done as Christian said, a fetch can be undone with git reset --hard , however all uncommitted changes in your tree will be lost as well as the changes you've fetched.
Brian Gianforcaro
Are you looking for `git reset --soft` or `--mixed`? Check the manpage.
Aristotle Pagaltzis
+15  A: 

After doing a git fetch, do a git log HEAD..origin to show the log entries between your last common commit and the origin branch. To show the diffs, use either git log -p HEAD..origin to show each patch, or git diff HEAD...origin (three dots not two) to show a single diff.

There normally isn't any need to undo a fetch, because doing a fetch only updates the remote branch and none of your branches. If you're not prepared to do a pull and merge in all the remote commits, you can use git cherry-pick to accept only the specific remote commits you want. Later, when you're ready to get everything, a git pull will merge in the rest of the commits.

Update: I'm not entirely sure why you want to avoid the use of git fetch. All git fetch does is update your local copy of a remote branch. This local copy doesn't have anything to do with any of your branches, and it doesn't have anything to do with uncommitted local changes. I have heard of people who run git fetch in a cron job because it's so safe.

Greg Hewgill
I guess I missed that part of 'nothing to do with MY branches' while reading the docs. Thanks.
Milan Babuškov