Re: [RFC/PATCH] Add git-unresolve <paths>...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Carl Worth <cworth@xxxxxxxxxx> writes:

> Meanwhile, I still think it's worth re-considering the original
> problem. 
>
> After a failed merge, I get a multi-parent diff from "git
> diff". However, after updating the index, I can't find any way to get
> multi-parent diffs anymore.
>
> I'd still like to be able to do that, even when I know that what I
> have in the index is good, and I don't want to undo it. So the
> proposed unresolve (or update-index --unmerge, or whatever) is still
> not totally satisfactory.

I suspect this is just a misunderstanding caused by insufficient
explanation, so let's try this a bit differently.

With the patch applied (or use "next" branch I'll be pushing out
shortly), let's try the core-tutorial example up to the point
where we need to make a merge commit and get conflict.

The easiest way to do it is to interrupt the t/t1200-tutorial.sh
sequence, like this:

------------
diff --git a/t/t1200-tutorial.sh b/t/t1200-tutorial.sh
index 16b3ea9..a51bb50 100755
--- a/t/t1200-tutorial.sh
+++ b/t/t1200-tutorial.sh
@@ -105,6 +105,8 @@ git commit -m 'Some fun.' -i hello examp
 
 test_expect_failure 'git resolve now fails' 'git resolve HEAD mybranch "Merge work in mybranch"'
 
+test_done
+
 cat > hello << EOF
 Hello World
 It's a new day for git
------------

Now, go to t/ directory and run this:

------------
$ cd t
$ ./t1200-tutorial.sh
------------

... which will stop after saying:

------------
*   ok 13: git resolve now fails
* passed all 13 test(s)
------------

Then go to t/trash directory to find the initial part of
Tutorial already run for us.  We have created a repository with
two files (`example` and `hello`), with two branches (`master`
and `mybranch`), and we are on `master`.  Both branches touched
`hello` in a conflicting way, and we have just pulled the other
branch into `master`, which conflicted, and hand resolved.

We can see the conflict like this:

------------
$ git diff
diff --cc hello
index ba42a2a,cc44c73..0000000
--- a/hello
+++ b/hello
@@@ -1,2 -1,3 +1,7 @@@
  Hello World
++<<<<<<< .merge_file_4wwUQv
 +Play, play, play
++=======
+ It's a new day for git
+ Work, work, work
++>>>>>>> .merge_file_6Ie4jx
------------

and we follow the tutorial to resolve it to see how the combined
diff looks like:

------------
$ cat >hello <<\EOF
Hello World
Play, play, play
It's a new day for git
Work, work, work
EOF
$ git diff
diff --cc hello
index ba42a2a,cc44c73..0000000
--- a/hello
+++ b/hello
@@@ -1,2 -1,3 +1,4 @@@
  Hello World
 +Play, play, play
+ It's a new day for git
+ Work, work, work
------------

Still with me so?  Now, let's say there was something wrong with
the above merge, but at this point we did not know about it.
For now, we are satisfied with this and run update-index:

------------
$ git update-index hello
$ git diff
------------

It was conflicting before, we hand-resolved and we said we are
done.  We do not see "git diff" output anymore, so we can
concentrate on other files.

But later (much later) we find out that there was something
wrong with this hand-resolve and now we would want to fix it.
The new command, "git unresolve" is designed to help us exactly
in this situation:

------------
$ git unresolve hello
$ git diff
diff --cc hello
index ba42a2a,cc44c73..0000000
--- a/hello
+++ b/hello
@@@ -1,2 -1,3 +1,4 @@@
  Hello World
 +Play, play, play
+ It's a new day for git
+ Work, work, work
------------

Then we realize that the "Play" line is not something we would
want in the merge result, because we are in serious business.
So let's drop it from the result and view the diff again:

------------
$ mv hello hellooo
$ sed -e '2d' <hellooo >hello
$ rm hellooo 
$ git diff
diff --cc hello
index ba42a2a,cc44c73..0000000
--- a/hello
+++ b/hello
------------

Oops, what happened?  There is no diff?

The default option "dense combined" (--cc) is stronger than
"combined" in that it omits hunks that have differences from
only one parent, and in this case we took "their" version, so
there is no interesting combined merge remaining to be seen.

If you want to view such not-so-interesting hunks, you could
give different option to "git diff", like so:

------------
$ git diff -c -p
diff --combined hello
index ba42a2a,cc44c73..0000000
--- a/hello
+++ b/hello
@@@ -1,2 -1,3 +1,3 @@@
  Hello World
- Play, play, play
+ It's a new day for git
+ Work, work, work
------------

Also we can use different options like '--ours' (view diff from
our branch) and '--theirs' (diff from their branch):

------------
$ git diff --ours hello
* Unmerged path hello
diff --git a/hello b/hello
index ba42a2a..cc44c73 100644
--- a/hello
+++ b/hello
@@ -1,2 +1,3 @@
 Hello World
-Play, play, play
+It's a new day for git
+Work, work, work
$ git diff --theirs hello
* Unmerged path hello
diff --git a/hello b/hello
------------


-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]