[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 <--mastera 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--*--*--*--*--*--*
^
|
masterSigned-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