git diff to see what a merge would introduce

旧街凉风 提交于 2020-01-01 06:11:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11727102/git-diff-to-see-what-a-merge-would-introduce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!