From: Marc Branchaud <marcnarc@xiplink.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <j.sixt@viscovery.net>,
Jonathan Nieder <jrnieder@gmail.com>,
Marc Branchaud <marcnarc@xiplink.com>
Subject: [PATCH] Test that the 'rebase -i' "reword" command always cherry-picks a commit.
Date: Mon, 22 Mar 2010 15:25:42 -0400 [thread overview]
Message-ID: <1269285942-17496-1-git-send-email-marcnarc@xiplink.com> (raw)
In-Reply-To: <4BA11B23.4090801@xiplink.com>
In particular, "reword" should cherry-pick a reworded commit even if the
commit's message is unchanged.
This behaviour provides a way to deal with a situation that can arise when
a merge had to be reverted. Added an addendum to revert-a-faulty-merge.txt
describing the situation and how to use "reword" to handle it.
---
Is this more acceptable than adding --no-ff to rebase--interactive?
I wasn't sure how to integrate the new text into revert-a-faulty-merge.txt.
I went with an addendum, but I'm open to other approaches.
M.
Documentation/howto/revert-a-faulty-merge.txt | 64 +++++++++++++++++++++++++
t/t3417-rebase-reword-forces-cherry-pick.sh | 59 +++++++++++++++++++++++
2 files changed, 123 insertions(+), 0 deletions(-)
create mode 100755 t/t3417-rebase-reword-forces-cherry-pick.sh
diff --git a/Documentation/howto/revert-a-faulty-merge.txt b/Documentation/howto/revert-a-faulty-merge.txt
index 3b4a390..892433d 100644
--- a/Documentation/howto/revert-a-faulty-merge.txt
+++ b/Documentation/howto/revert-a-faulty-merge.txt
@@ -142,6 +142,8 @@ different resolution strategies:
revert of a merge was rebuilt from scratch (i.e. rebasing and fixing,
as you seem to have interpreted), then re-merging the result without
doing anything else fancy would be the right thing to do.
+ (See the ADDENDUM below for how to rebuild a branch from scratch
+ without changing its original branching-off point.)
However, there are things to keep in mind when reverting a merge (and
reverting such a revert).
@@ -177,3 +179,65 @@ the answer is: "oops, I really shouldn't have merged it, because it wasn't
ready yet, and I really need to undo _all_ of the merge"). So then you
really should revert the merge, but when you want to re-do the merge, you
now need to do it by reverting the revert.
+
+ADDENDUM
+
+Sometimes you're in a situation like this
+
+ P---o---o---M---x---x---W---x
+ \ /
+ A---B---C
+
+where you:
+
+ - Need to rewrite one of the commits on the A-B-C branch; and
+
+ - Want the rewritten A-B-C branch to still start at commit P (perhaps P
+ is a branching-off point for yet another branch, and you want be able to
+ merge A-B-C into both branches).
+
+The natural thing to do in this case is to checkout the A-B-C branch and use
+"rebase -i A" to change commit B. However, this does not rewrite commit A,
+and you end up with this:
+
+ P---o---o---M---x---x---W---x
+ \ /
+ A---B---C <-- old branch
+ \
+ B'---C' <-- rewritten branch
+
+To merge A-B'-C' into the mainline branch you would still have to first revert
+commit W in order to pick up the changes in A, but then it's likely that the
+changes in B' will conflict with the original B changes re-introduced by the
+reversion of W.
+
+However, you could avoid these problems if you recreated the entire branch,
+including commit A:
+
+ P---o---o---M---x---x---W---x
+ |\ /
+ | A---B---C <-- old branch
+ \
+ A'---B'---C' <-- entirely recreated branch
+
+Now you can merge A'-B'-C' into the mainline branch without worrying about
+first reverting W.
+
+But if you don't actually need to change commit A, then you need some way to
+recreate it as a new commit with the same changes in it. One way to do this
+is to use the "reword" command in "rebase -i". If you:
+
+ - Checkout the A-B-C branch
+
+ - Run "rebase -i P" to rebase the entire branch
+
+ - "reword" commit A (the first commit in the rebase script)
+
+ - Make NO changes to commit A's message
+
+then you'll end up with a new branch A'-B'-C' with all-new commits (all the
+SHA IDs will be different) but that has the same changes that were in the
+original A-B-C branch.
+
+You can then modify commit B' as you like and merge the new A'-B''-C' branch
+into the mainline branch without first reverting commit W.
diff --git a/t/t3417-rebase-reword-forces-cherry-pick.sh b/t/t3417-rebase-reword-forces-cherry-pick.sh
new file mode 100755
index 0000000..3e29f0f
--- /dev/null
+++ b/t/t3417-rebase-reword-forces-cherry-pick.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Marc Branchaud
+#
+
+test_description='git rebase interactive "reword" always forces cherry-pick
+
+This test ensures that the "reword" command of "git rebase -i" cherry-picks
+a reworded commit even if no changes are made to the commit message.
+
+This behaviour provides a way to deal with a situation that can arise when a
+merge had to be reverted. For details, see the ADDENDUM in
+Documentation/howto/revert-a-faulty-merge.txt.
+'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+set_fake_editor
+
+# A simple linear history.
+test_expect_success 'setup' '
+ test_commit A file1 &&
+ test_commit B file1 &&
+ test_commit C file1 &&
+ test_commit D file1 &&
+ git branch old-master HEAD
+'
+
+# Ensure that the rebased commits get a different timestamp.
+test_tick
+
+# Reword the first commit, but don't actually change the message
+test_expect_success 'reword' '
+ FAKE_LINES="reword 1 2 3" git rebase -i A
+'
+
+# There should be no textual differences between the old and new branches.
+# However:
+# - Commit A should be completely unchanged.
+# - Commits B, C and D should have different SHA IDs.
+test_expect_success 'verify' '
+ touch empty &&
+ test ! $(git rev-parse ) = $(git rev-parse master) &&
+ git diff old-master master > out &&
+ test_cmp empty out &&
+ test ! $(git rev-parse C) = $(git rev-parse master^) &&
+ git diff old-master^ master^ > out &&
+ test_cmp empty out &&
+ test ! $(git rev-parse B) = $(git rev-parse master^^) &&
+ git diff old-master^^ master^^ > out &&
+ test_cmp empty out &&
+ test $(git rev-parse A) = $(git rev-parse master^^^) &&
+ git diff old-master^^^ master^^^ > out &&
+ test_cmp empty out
+'
+
+test_done
--
1.7.0.3
next prev parent reply other threads:[~2010-03-22 19:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-16 16:08 [PATCH] Teach --no-ff option to 'rebase -i' Marc Branchaud
2010-03-16 19:19 ` Marc Branchaud
2010-03-16 19:42 ` [PATCHv2] " Marc Branchaud
2010-03-16 21:47 ` Jonathan Nieder
2010-03-17 6:59 ` Johannes Sixt
2010-03-17 15:58 ` Peter Baumann
2010-03-17 16:07 ` Johannes Sixt
2010-03-17 18:42 ` Peter Baumann
2010-03-18 7:08 ` Johannes Sixt
2010-03-18 8:03 ` Peter Baumann
2010-03-17 16:03 ` Marc Branchaud
2010-03-17 16:19 ` Johannes Sixt
2010-03-17 18:10 ` Marc Branchaud
2010-03-22 19:25 ` Marc Branchaud [this message]
2010-03-22 20:23 ` [PATCH] Test that the 'rebase -i' "reword" command always cherry-picks a commit Avery Pennarun
2010-03-22 22:06 ` Marc Branchaud
2010-03-22 20:46 ` Junio C Hamano
2010-03-23 14:38 ` Marc Branchaud
2010-03-23 16:19 ` [PATCHv3] Teach -f/--force-rebase option to 'rebase -i' Marc Branchaud
2010-03-23 22:42 ` Junio C Hamano
2010-03-24 15:40 ` [PATCHv4 0/2] Teach the --no-ff " Marc Branchaud
2010-03-24 17:13 ` Junio C Hamano
2010-03-24 20:34 ` [PATCHv5] Teach rebase the --no-ff option Marc Branchaud
2010-03-24 21:45 ` Junio C Hamano
2010-03-24 15:41 ` [PATCH 1/2] Teach 'rebase -i' to accept and ignore the -f/--force-rebase option Marc Branchaud
2010-03-24 15:41 ` [PATCH 2/2] Teach the --no-ff option to 'rebase -i' Marc Branchaud
2010-03-24 19:06 ` Junio C Hamano
2010-03-23 19:16 ` [PATCH] Test that the 'rebase -i' "reword" command always cherry-picks a commit Jonathan Nieder
2010-03-22 22:09 ` Jonathan Nieder
2010-03-17 15:56 ` [PATCHv2] Teach --no-ff option to 'rebase -i' Marc Branchaud
2010-03-17 17:53 ` Jonathan Nieder
2010-03-17 18:13 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269285942-17496-1-git-send-email-marcnarc@xiplink.com \
--to=marcnarc@xiplink.com \
--cc=git@vger.kernel.org \
--cc=j.sixt@viscovery.net \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).