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

[PATCH RFC 4/4] rebase -i: add --refs option to rewrite heads within branch

From
Greg Price <price@ksplice.com>
Date
Dec 22, 2009, 22:23 UTC
Message-ID
<20091222222316.GY30538@dr-wily.mit.edu>
In-Reply-To
<20091222222032.GU30538@dr-wily.mit.edu>

The new option --refs causes the TODO file to contain a "ref" command for each head pointing to a selected commit, other than the one we are already rebasing. The effect of this is that when a branch contains intermediate branches, like so:

      part1 part2 topic
        |     |     |
        v     v     v
  A--*--*--*--*--*--*
   \
    B <--master

a single command like "git rebase -i --refs master topic" suffices to rewrite all the heads that are part of the topic, like so:

        part1 part2 topic
  A       |     |     |
   \      v     v     v
    B--*--*--*--*--*--*
    ^
    |
    master
Signed-off-by: Greg Price <price@ksplice.com>
---
 git-rebase--interactive.sh |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 25ac3e3..cccb031 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -18,6 +18,7 @@ git-rebase [-i] (--continue | --abort | --skip)
  Available options are
 v,verbose          display a diffstat of what changed upstream
 onto=              rebase onto given branch instead of upstream
+refs               rewrite intermediate heads on branch
 p,preserve-merges  try to recreate merges instead of ignoring them
 s,strategy=        use the given merge strategy
 m,merge            always used (no-op)
@@ -42,6 +43,7 @@ REWRITTEN="$DOTEST"/rewritten
 DROPPED="$DOTEST"/dropped
 PRESERVE_MERGES=
 STRATEGY=
+REWRITE_REFS=
 ONTO=
 VERBOSE=
 OK_TO_SKIP_PRE_REBASE=
@@ -578,6 +580,9 @@ first and then run 'git rebase --continue' again."
 
 		output git reset --hard && do_rest
 		;;
+	--refs)
+		REWRITE_REFS=t
+		;;
 	-s)
 		case "$#,$1" in
 		*,*=*)
@@ -705,11 +710,14 @@ first and then run 'git rebase --continue' again."
 			REVISIONS=$ONTO...$HEAD
 			SHORTREVISIONS=$SHORTHEAD
 		fi
-		git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-			--abbrev=7 --reverse --left-right --topo-order \
+		git rev-list $MERGES_OPTION --abbrev-commit --abbrev=7 \
+			--reverse --left-right --topo-order \
+			--pretty=format:"$(printf '%%m%%h %%s\n%%m%%D')" \
 			$REVISIONS | \
 			sed -n "s/^>//p" | while read shortsha1 rest
 		do
+			read refs
+
 			if test t != "$PRESERVE_MERGES"
 			then
 				echo "pick $shortsha1 $rest" >> "$TODO"
@@ -734,6 +742,16 @@ first and then run 'git rebase --continue' again."
 					echo "pick $shortsha1 $rest" >> "$TODO"
 				fi
 			fi
+
+			if test t = "$REWRITE_REFS"
+			then
+				for ref in $refs
+				do
+					test ${ref#refs/heads/} != $ref &&
+					test $ref != $(cat "$DOTEST"/head-name) &&
+					echo "ref $ref" >> "$TODO"
+				done
+			fi
 		done
 
 		# Watch for commits that been dropped by --cherry-pick
-- 
1.6.6.rc1.9.g2ad41.dirty
Previous: Greg PriceNext: Junio C Hamano
Message 5 of 11 in “rebase -i: Add --refs option to rewrite heads within branch”
  1. 0/4 rebase -i: Add --refs option to rewrite heads within branchGreg Price, Dec 22, 2009
  2. 1/4 pretty: Add %D for script-friendly decorationGreg Price, Dec 22, 2009
  3. 2/4 log --decorate=full: drop the "tag: " prefixGreg Price, Dec 22, 2009
  4. 3/4 rebase -i: Add the "ref" commandGreg Price, Dec 22, 2009
  5. 4/4 rebase -i: add --refs option to rewrite heads within branchGreg Price, Dec 22, 2009
  6. Junio C HamanoDec 22, 2009
  7. Greg PriceDec 23, 2009
  8. Michael J GruberDec 23, 2009
  9. Greg PriceDec 23, 2009
  10. Junio C HamanoDec 23, 2009
  11. Johannes SchindelinDec 23, 2009

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.