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

[PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff

From
Andrew Wong <andrew.kw.w@gmail.com>
Date
Apr 21, 2011, 03:38 UTC
Message-ID
<1303357080-25840-1-git-send-email-andrew.kw.w@gmail.com>

'git rebase' uses 'git merge' to preserve merges (-p). This preserves the original merge commit correctly, except when the original merge commit was created by 'git merge --no-ff'. In this case, 'git rebase' will fail to preserve the merge, because during 'git rebase', 'git merge' will simply fast-forward and skip the commit. For example:

               B
              / \
             A---M
            /
    ---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
                 A---B
                /
    ---o---O---P---Q

To correct this, we simply do a "no fast-forward" on all merge commits when rebasing. Since by the time we decided to do a 'git merge' inside 'git rebase', it means there was a merge originally, so 'git merge' should always create a merge commit regardless of what the merge branches look like. This way, when rebase M onto P from the above example, we get:

                   B
                  / \
                 A---M
                /
    ---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
 git-rebase--interactive.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..c308529 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -339,7 +339,7 @@ pick_one_preserving_merges () {
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
 			if ! do_with_author output \
-				git merge $STRATEGY -m "$msg" $new_parents
+				git merge --no-ff $STRATEGY -m "$msg" $new_parents
 			then
 				printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
 				die_with_patch $sha1 "Error redoing merge $sha1"
-- 
1.7.2.2
Next: Andrew Wong
Message 1 of 6 in “git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff”
  1. git-rebase--interactive.sh: preserve-merges fails on merges created with no-ffAndrew Wong, Apr 21, 2011
  2. Andrew WongApr 27, 2011
  3. Junio C HamanoApr 27, 2011
  4. Christian CouderApr 27, 2011
  5. Junio C HamanoApr 27, 2011
  6. git-rebase--interactive.sh: preserve-merges fails on merges created with no-ffAndrew Wong, Apr 28, 2011

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.