git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <junkio@cox.net>
Date
Apr 19, 2006, 23:57 UTC
Message-ID
<7vmzeh3ypu.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<87wtdl2o5o.wl%cworth@cworth.org>
Carl Worth <cworth@cworth.org> writes:
Show 11 quoted lines
> 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
------------
Previous: Carl WorthNext: Carl Worth
Message 9 of 11 in “Add git-unresolve <paths>...”
  1. Add git-unresolve <paths>...Junio C Hamano, Apr 19, 2006
  2. Carl WorthApr 19, 2006
  3. Junio C HamanoApr 19, 2006
  4. git-merge: a bit more readable user guidance.Junio C Hamano, Apr 19, 2006
  5. pre-commit hook: complain about conflict markers.Junio C Hamano, Apr 19, 2006
  6. Carl WorthApr 19, 2006
  7. Junio C HamanoApr 19, 2006
  8. Carl WorthApr 20, 2006
  9. Junio C HamanoApr 19, 2006
  10. Carl WorthApr 20, 2006
  11. Junio C HamanoApr 20, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.