git diff to see what a merge would introduce
Asked Answered
P

1

6

So me and a friend have been working on a project. Most of the time merges are painless as we generally work in different areas.

Recently we have been running into eachother more and more creating nasty merges (deadlines).

So we began investigating ways to see what a merge would do. I found a way to use git diff:

git diff mybranch...hisbranch

This gives pretty good results. The problem is, since that it uses the last common ancestor, and that ancestor is getting farther and farther back there is a lot of junk in the merge that hasn't been changed in either of our branches.

So I'm wondering is there a way to visualize exactly what a merge would do.

I've tried:

git diff $(git-merge mybranch hisbranch) hisbranch

Which seems to work ok, but I want to visualize the merge the other way so I tried:

git diff $(git-merge hisbranch mybranch) mybranch

But in this case git-merge: command not found

Does anyone know of a good way to get a diff of two branches showing what a merge would introduce? Maybe highlight conflicts?

If not, is there any visual tool that will allow one to manually do a commit, so one can choose what version of the code is the best.

Preliminary answered 30/7, 2012 at 18:8 Comment(1)
“But in this case git-merge: command not found” This “hyphen-style” eventually got deprecated and removed in favor of always using git merge.Technocracy
P
9

There are other ways to visualize what would happen, but I find the easiest is git merge --no-commit. From the man page:

--commit, --no-commit
Perform the merge and commit the result. This option can be used to override --no-commit.

With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge
result before committing.

Basically, I just issue git merge --no-commit <branch> and inspect the results. If I don't like them, I issue git merge --abort, or if I want to commit the merge, I proceed normally with git commit.

Promethium answered 30/7, 2012 at 20:31 Comment(2)
Is there anyway to see what exactly was changed? Maybe diff this no-commit merge code with HEAD.Preliminary
Sure. After issuing the --no-commit merge, git diff --cached will show you exactly what's staged, and git diff (with no arguments) will show you conflicted files.Promethium

© 2022 - 2024 — McMap. All rights reserved.