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

[PATCH 2/2] Use branch names in 'git-rebase -m' conflict hunks.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 28, 2006, 01:43 UTC
Message-ID
<20061228014340.GB16790@spearce.org>
In-Reply-To
<35ce346ffc16a7c294a8a1e69e604dfec81d288f.1167270210.git.spearce@spearce.org>

If a three-way merge in git-rebase generates a conflict then we should take advantage of git-merge-recursive's ability to include the branch name of each side of the conflict hunk by setting the GITHEAD_* environment variables.

In the case of rebase there aren't really two clear branches; we have the branch we are rebasing onto, and we have the branch we are currently rebasing. Since most conflicts will be arising between the user's current branch and the branch they are rebasing onto we assume the stuff that isn't in the current commit is the "onto" branch and the stuff in the current commit is the "current" branch.

This assumption may however come up wrong if the user resolves one conflict in such a way that it conflicts again on a future commit also being rebased. In this case the user's prior resolution will appear to be in the "onto" part of the hunk.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-rebase.sh |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index b99f1e3..1f00cb0 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -80,10 +80,18 @@ continue_merge () {
 call_merge () {
 	cmt="$(cat $dotest/cmt.$1)"
 	echo "$cmt" > "$dotest/current"
-	git-merge-$strategy "$cmt^" -- HEAD "$cmt"
+	hd=$(git-rev-parse --verify HEAD)
+	cmt_name=$(git-symbolic-ref HEAD)
+	msgnum=$(cat $dotest/msgnum)
+	end=$(cat $dotest/end)
+	eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
+	eval GITHEAD_$hd='"$(cat $dotest/onto_name)"'
+	export GITHEAD_$cmt GITHEAD_$hd
+	git-merge-$strategy "$cmt^" -- "$hd" "$cmt"
 	rv=$?
 	case "$rv" in
 	0)
+		unset GITHEAD_$cmt GITHEAD_$hd
 		return
 		;;
 	1)
@@ -316,6 +324,7 @@ fi
 
 mkdir -p "$dotest"
 echo "$onto" > "$dotest/onto"
+echo "$onto_name" > "$dotest/onto_name"
 prev_head=`git-rev-parse HEAD^0`
 echo "$prev_head" > "$dotest/prev_head"
 
-- 
1.4.4.3.gd2e4
Message 1 of 1 in “Use branch names in 'git-rebase -m' conflict hunks.”
  1. 2/2 Use branch names in 'git-rebase -m' conflict hunks.Shawn O. Pearce, Dec 28, 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.