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

Re: re-running merge on a single file

From
Chris Packham <judge.packham@gmail.com>
Date
Mar 12, 2010, 20:16 UTC
Message-ID
<a038bef51003121216l5c0a4942qabc3d12741c9030e@mail.gmail.com>
In-Reply-To
<7viq92rpsr.fsf@alter.siamese.dyndns.org>
On Thu, Mar 11, 2010 at 10:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
>
>> Chris Packham schrieb:
>>> $ git checkout --merge -- cpu/mpc83xx/start.S
>>> $ git show :1:$(git rev-parse --show-prefix)cpu/mpc83xx/start.S
>>> fatal: Path 'cpu/mpc83xx/start.S' is in the index, but not at stage 1.
>>> Did you mean ':0:cpu/mpc83xx/start.S'?
>>
>> Both of these work only as long as the index still records the conflicted
>> state. If you (or one of your tools) has git-added the file, or you have
>> git-checked-out some version of the file, the conflict stages are lost,
>> and you must reset --hard and redo the entire merge.
>
> If the merge textually autoresolves cleanly, you might not even have any
> conflicted state to begin with.  In such a case you would need to grab
>
>        MERGE_HEAD:path-to-that-thing
>        HEAD:path-to-that-thing
>
> yourself.
>

So if I understand correctly once I've committed the merge the various stages and MERGE_HEADs go away. I don't really want to re-do the whole merge which is probably the correct thing to do. I'm lazy and my projects rules allow broken commits so instead I can poke about with git show and various revisions.

Here's a simple script that does just that. I've borrowed some command line options from git mergetool (Warning: gmail web interface). If anyone is interested in seeing a proper version of this I can clean it up submit it properly.

----8<----
From c6ad177712422cbba641975d9e6a5fe85fc8f1fa Mon Sep 17 00:00:00 2001
From: Chris Packham <judge.packham@gmail.com>
Date: Fri, 12 Mar 2010 12:03:02 -0800
Subject: [PATCH] Add git manual-merge command
Can be used to manually merge files from the specified revisions.
---
 git-manual-merge |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100755 git-manual-merge
diff --git a/git-manual-merge b/git-manual-merge
new file mode 100755
index 0000000..f37ba88
--- /dev/null
+++ b/git-manual-merge
@@ -0,0 +1,91 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Chris Packham
+#
+# Based on git-mergetool by Theodore Y. Ts'o
+#
+# This file is licensed under the GPL v2
+#
+
+USAGE='<branch1> <branch2> <file> ...'
+. git-sh-setup
+. git-mergetool--lib
+require_work_tree
+
+merge_one_file()
+{
+    local has_base=false
+    git show $1:$4 > $4.$1 && has_base=true
+    git show $2:$4 > $4.$2 || die
+    git show $3:$4 > $4.$3 || die
+
+    if "$prompt" = true; then
+       printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
+       read ans
+    fi
+
+    if "$has_base" = true; then
+        $merge_tool $4.$1 $4.$2 $4.$1 -o $4
+    else
+        $merge_tool $4.$2 $4.$1 -o $4
+    fi
+}
+
+prompt=$(git config --bool mergetool.prompt || echo true)
+
+while test $# != 0
+do
+    case "$1" in
+        -t|--tool*)
+            case "$#,$1" in
+                *,*=*)
+                    merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
+                    ;;
+                1,*)
+                    usage ;;
+                *)
+                    merge_tool="$2"
+                    shift ;;
+            esac
+            ;;
+        -y|--no-prompt)
+            prompt=false
+            ;;
+        --prompt)
+            prompt=true
+            ;;
+        --)
+            shift
+            break
+            ;;
+        -*)
+            usage
+            ;;
+        *)
+            break
+            ;;
+    esac
+    shift
+done
+
+echo "$merge_tool"
+
+if test $# -lt 3; then
+    usage
+fi
+
+branch1=$(git rev-parse --short  $1)
+branch2=$(git rev-parse --short  $2)
+_base=$(git merge-base $branch1 $branch2)
+base=$(git rev-parse --short  $_base)
+
+if test -z "$merge_tool"; then
+    merge_tool=$(get_merge_tool "$merge_tool") || exit
+fi
+
+shift 2
+
+for x in $*; do
+    merge_one_file $base $branch1 $branch2 $x
+done
+
--
1.7.0.1
Previous: Junio C HamanoNext: Chris Packham
Message 9 of 14 in “re-running merge on a single file”
  1. Chris PackhamMar 11, 2010
  2. Chris PackhamMar 11, 2010
  3. Markus HeidelbergMar 11, 2010
  4. Chris PackhamMar 11, 2010
  5. Jakub NarebskiMar 11, 2010
  6. Chris PackhamMar 12, 2010
  7. Johannes SixtMar 12, 2010
  8. Junio C HamanoMar 12, 2010
  9. Chris PackhamMar 12, 2010
  10. Chris PackhamMar 12, 2010
  11. Junio C HamanoMar 12, 2010
  12. Chris PackhamMar 12, 2010
  13. Kris ShannonMar 14, 2010
  14. Jakub NarebskiMar 12, 2010

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.