views:

2610

answers:

2

I'm merging in a remote branch that may have a lot of conflicts. How can I tell if it will have conflicts or not?

I don't see anything like a --dry-run on git-merge.

+18  A: 

As noted previously, pass in the --no-commit flag, but to avoid a fast-forward commit, also pass in --no-ff, like so:

$ git merge --no-commit --no-ff $BRANCH

This will allow you to examine/undo the merge, even if it is a fast-forward merge.

mipadi
This is great, but will still modify your working copy. If your repo is a live webserver then you could be serving files with conflicts in.
dave1010
You can't really do a merge without affecting the working copy.
mipadi
True, but something like `git merge --only-if-there-wont-be-any-conflicts` or `git diff --show-conflicts <commit>` would be really handy. Shame it's not possible yet, or am I missing something?
dave1010
`git merge --ff-only` will only try to "merge" if your current HEAD commit is in the branch you're merging in. This will allow you to merge some commits whilst being sure you won't get conflicts. Many merges aren't fastforwards, so this won't always work.
dave1010
+5  A: 

Undoing a merge with git is so easy you shouldn't even worry about the dry run:

$ git pull $REMOTE $BRANCH
# uh oh, that wasn't right
$ git reset --hard ORIG_HEAD
# all is right with the world
Brian Phillips
True, but in this case I had done the complex merge in a branch off master and wanted to be 100% sure it was a good FF merge. Had it not been I'd have gone back to the other branch and done something similar to your answer to get it in shape.
Otto