What is the first section in the git rerere diff output?

130 views Asked by At

I am working through the Git - Rerere section of the Git Book. I have just run git checkout master; git merge rerere2; git rerere diff. Here is the output.

PS> git rerere diff
--- a/simple.rb
+++ b/simple.rb
@@ -1,9 +1,9 @@
 #! /usr/bin/env ruby

 def hello
-<<<<<<<
-  puts 'hello mondo'
-=======
+<<<<<<< HEAD
   puts 'hola world'
->>>>>>>
+=======
+  puts 'hello mondo'
+>>>>>>> rerere2
 end

There are three diff sections.

  1. <<<<<<< shows what?
  2. <<<<<<< HEAD shows what the HEAD branch wants to contribute.
  3. >>>>>>> rerere2 shows what the rerere2 branch wants to contribute.

It looks like the first diff section is a negation of what rerere2 wants to contribute. That doesn't make sense to me, though. What does the first section mean?

2

There are 2 answers

2
Shaun Luttin On

Answer

Asking what the first section of git rerere diff means is fine but misguided. Instead, examine the - and + annotations. From the Git Book:

git rerere diff will show the current state of the resolution - what you started with to resolve and what you’ve resolved it to.

Anything prefixed with - or no prefix is what you started with to resolve:

<<<<<<<                           
  puts 'hello mondo'              
=======
  puts 'hola world'                           
>>>>>>>

Anything prefixed with + or no prefix is what you've resolved it to (and is what you currently have in your working dir):

<<<<<<< HEAD                      
   puts 'hola world'               
=======                           
  puts 'hello mondo'              
>>>>>>> rerere2                   

Detailed Explanation

Contents of Working Dir

Immediately after merge, the working directory contains:

def hello
<<<<<<< HEAD
  puts 'hola world'
=======
  puts 'hello mondo'
>>>>>>> rerere2
end

Output of git diff

The output of git diff is this and uses the combined diff markup:

  def hello
++<<<<<<< HEAD                    in working dir but in neither ours/theirs
 +  puts 'hola world'             in working dir but not in theirs
++=======                         in working dir but in neither ours/theirs
+   puts 'hello mondo'            in working dir but not in ours
++>>>>>>> rerere2                 in working dir but in neither ours/theirs
  end

If we look at the working dir file of simple.rb, this is true. It's contents are the same as the git diff output but without the ours/theirs markers.

Output of git rerere diff

And the output of git rerere diff is this and does NOT use the combined diff format.

 def hello                              
-<<<<<<<                            started with
-  puts 'hello mondo'               started with
-=======                            started with
+<<<<<<< HEAD                       resolved to
   puts 'hola world'                started with & resolved to
->>>>>>>                            started with
+=======                            resolved to
+  puts 'hello mondo'               resolved to
+>>>>>>> rerere2                    resolved to
 end
  • anything with a - is part of what you've started with
  • anything with a + is part of what you've resolved to
  • anything with no prefix is part of both

If we look at just what has the - annotation, we have this:

-<<<<<<<                           
-  puts 'hello mondo'              
-=======                           
->>>>>>>

That says that the left side brings in puts 'hello mondo' and the right side brings in nothing. If we look at just what has the +, we have this:

+<<<<<<< HEAD                      
   puts 'hola world'               
+=======                           
+  puts 'hello mondo'              
+>>>>>>> rerere2                   

That's exactly what is in the working directory right now.

8
Fermis On

From that link

git rerere diff will show the current state of the resolution - what you started with to resolve and what you've resolved it to.

git rerere saves merging choices. So it's describing the thing's it's going to do. First section is one of the inputs for resolution. Last section is the output of the merge.

$ git rerere diff
--- a/hello.rb
+++ b/hello.rb
@@ -1,11 +1,11 @@
 #! /usr/bin/env ruby

 def hello
-<<<<<<<
-  puts 'hello mundo'
-=======
+<<<<<<< HEAD
   puts 'hola world'
->>>>>>>
+=======
+  puts 'hello mundo'
+>>>>>>> i18n-world
 end

This section is telling you what it's thinking about doing. It wants to take out hello mundo from one file and hola world from another and replace it with hello mundo.

$ git rerere diff
--- a/hello.rb
+++ b/hello.rb
@@ -1,11 +1,7 @@
 #! /usr/bin/env ruby

 def hello
-<<<<<<<
-  puts 'hello mundo'
-=======
-  puts 'hola world'
->>>>>>>
+  puts 'hola mundo'
 end

Takes "hello mundo" and "hola world" and replaces that line with hola mundo