Pregunta

In Bazaar if you have a conflict in foo.html it will make an additional 3 files

foo.html.BASE
foo.html.OTHER
foo.html.THIS

Then you can

diff -Naur foo.html.BASE foo.html.OTHER

Comparing the common basis with the other set of changes is really helpful because it tells you what, exactly, they changed, which helps answer why they did it. For example, if all they changed was white space, you can confidently use your own change.

How do I accomplish this in git?

¿Fue útil?

Solución

git doesn't store the actual full-copy versions of the three files in your working directory. Instead, it stores a single file that has conflict markers placed in it. However, you can still get at those versions using the :<stage>:<filename> syntax (to git tools - the files don't actually exist, so, e.g. normal diff won't see them). So, for example, you can run git diff :1:foo.html :2:foo.html to see the differences between BASE and THIS. Stage 3 would be your OTHER version. You could also use git mergetool foo.html or git difftool foo.html. If you really need to use a non-git tool on them, you can do this:

git show :1:foo.html > foo.html.BASE
git show :2:foo.html > foo.html.THIS
git show :3:foo.html > foo.html.OTHER
diff ......

Otros consejos

To get a simple diff between to files in an external tool, you can use git difftool.

In a conflict resolution situation, you can also use git mergetool.

They share a certain set of configuration and usage options, but git mergetool will actually create files similar to the one you know from Bazaar. The details about this are described in the man pages linked above.

difftool and mergetool know some of the common diff and merge tools and can use them without further configuration (e.g. vimdiff, meld, k3diff, etc.), but you can configure your own or use the custom options to change the behaviour of those tools.

You should try to get mergetool to do what you want (for example, mergetool can be configured to not delete those files after the merge tool exits, so you can inspect them further). Now that you have a starting point, Google will also help, especially if the man pages are too technical for your taste.

If you run into specific problems, you can open a new question ;)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top