2

In Subversion, I can see what files would be affected by an update, without actually performing the update, with

svn status -u

Git doesn not have such a command. The usual suggestion for this problem is to do a fetch first. This is described here and here. The latter article also contains a nicely written explanation, why the fetch is necessary.

I stumbled today over a discussion of this theme which suggested a different approach, which is to use

git pull --dry-run

Now this makes me wonder:

  1. Does it really work? How can it do it without also doing a fetch?
  2. svn pull --help does NOT explain about the --dry-run switch, but if I use it, git does not complain that it is an illegal option either. Is this kind of "undocumented feature"?
Community
  • 1
  • 1
user1934428
  • 19,864
  • 7
  • 42
  • 87
  • 1
    The git documentation is known to have some room for improvement, so it's entirely possible that this option is undocumented. But the option is descibed in the [fetch documetation](https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html). – Sascha Wolf Dec 17 '14 at 10:45

1 Answers1

3

A quick test of git pull --dry-run shows that it is equivalent to git fetch --dry-run. It doesn't actually fetch anything, it just shows the SHA1s of what would be fetched. This isn't very useful IMHO.

git pull is equivalent to git fetch followed by git merge. Parameters that are valid for either of those commands will normally be passed through, where that makes sense.

If by "an update" you mean git pull, then if you split it into the equivalent running git fetch and git merge commands, you can inspect the state in between to determine what would be merged / fetched. Another option in git is to do the pull, inspect what happens, and undo it if it does something you don't want.

If it has a merge conflict, you can use git merge --abort. If it doesn't, you can use git reset to put the branch back to the previous SHA1.

rjmunro
  • 27,203
  • 20
  • 110
  • 132
  • 1
    `git pull` tries to pass options it doesn't know to `git fetch` and `git merge`. This means that `git pull --dry-run` is effectively the same as `git fetch --dry-run`. – Sascha Wolf Dec 17 '14 at 11:11