0

I'm asking about svn feature which I want to know whether it exists for git or not:

When svn has conflicts, it creates some additional files which are sometimes useful:

See https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-dug-conflicts.html

filename.mine - my original file as it existed at the working directory.

filename.BASE_REVISION - The file which is the BASE revision before you updated your working copy. It is the file checked out before you made your latest edits.

filename.NEW_REVISION - This is the file that Subversion client just received from the server. Actually this is the file we want to merge with.

This is useful, as sometimes, I want to compare the my local changes with base, or the remote changes with base. or simply select one file, and set it as the resolution of the conflict.

Using git, and getting conflicts, I see the file at the working dir is full with the '>>>' '<<<' signs.

Can I get from git similar behavior like svn, having these additional files? I've looked at git documentation, and did not find something appropriate.

Any idea?

Eliyahu Machluf
  • 1,251
  • 8
  • 17

2 Answers2

2

If you want to see the base version of a conflict (which is a must, if you ask me), it can be achieved by setting merge.conflictStyle to diff3 . And I see this in git help merge:

4. For conflicting paths, the index file records up to three versions: stage 1 stores
   the version from the common ancestor, stage 2 from HEAD, and stage 3 from
   MERGE_HEAD (you can inspect the stages with git ls-files -u). The working tree
   files contain the result of the "merge" program; i.e. 3-way merge results
   with familiar conflict markers <<< === >>>.

So, with git ls-files -u you will get the list of files, for a conflict, you will get something like:

$ git ls-files -u
  100755 ac51efdc3df4f4fd328d1a02ad05331d8e2c9111 1 hello.rb
  100755 36c06c8752c78d2aff89571132f3bf7841a7b5c3 2 hello.rb
  100755 e85207e04dfdd5eb0a1e9febbc67fd837c44a1cd 3 hello.rb

Then you can do this:

git show :1:hello.rb # common ancestor
git show :2:hello.rb # HEAD
git show :3:hello.rb # the other branch

Use redirection if you would like to have them as files for analysis purposes.

Info from https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I want to get the conflict with 3 different files: base file, my working file, and the file I want to merge with. Setting the style to diff3, does not create 3 files, but have the changes all at the same file. – Eliyahu Machluf Jun 26 '19 at 14:22
  • added more info to get the files from index – eftshift0 Jun 26 '19 at 14:41
  • Thanks. it really works, though I feel it is a little clumsy to use redirection, I would like to have some configuration field which will tell git this is the behavior I want. I can also have this redirection by writing a script for that. I'll wait a while to see if there are other answers, and if not, I'll mark this answer as resolving the issue. – Eliyahu Machluf Jun 26 '19 at 15:02
0

Finally I found a simpler way to create these files, though it is not straightforward.

git mergetool command generates the desired files. If I run the command with non existent merge tool for a given conflicted file, it generates the base file, local file, and remote file similar to what svn generates:

git mergetool --tool whatever a.txt

gives output:

Merging:
a.txt
Normal merge conflict for 'a.txt':
   {local}: modified file
   {remote}: modified file
Unknown merge tool whatever

now ls shows new files named 'a_BASE','a_LOCAL','a_REMOTE' (with process id added to filename) were created:

$ ls
a.txt  a_BACKUP_9348.txt  a_BASE_9348.txt  a_LOCAL_9348.txt  a_REMOTE_9348.txt
Eliyahu Machluf
  • 1,251
  • 8
  • 17