From df5df20c1308f936ea542c86df1e9c6974168472 Mon Sep 17 00:00:00 2001 From: Chris Webb Date: Tue, 26 Jun 2012 22:55:23 +0100 Subject: rebase -i: support --root without --onto Allow --root to be specified to rebase -i without --onto, making it possible to edit and re-order all commits right back to the root(s). If there is a conflict to be resolved when applying the first change, the user will expect a sane index and working tree to get sensible behaviour from git-diff and friends, so create a sentinel commit with an empty tree to rebase onto. Automatically squash the sentinel with any commits rebased directly onto it, so they end up as root commits in their own right and retain their authorship and commit message. Implicitly use rebase -i for non-interactive rebase of --root without an --onto argument now that rebase -i can correctly do this. Signed-off-by: Chris Webb Signed-off-by: Junio C Hamano --- git-rebase.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'git-rebase.sh') diff --git a/git-rebase.sh b/git-rebase.sh index e616737444..bde2be88a0 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -31,7 +31,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_KEEPDASHDASH= OPTIONS_SPEC="\ git rebase [-i] [options] [--onto ] [] [] -git rebase [-i] [options] --onto --root [] +git rebase [-i] [options] [--onto ] --root [] git-rebase [-i] --continue | --abort | --skip -- Available options are @@ -364,6 +364,11 @@ and run me again. I am stopping in case you still have something valuable there.' fi +if test -n "$rebase_root" && test -z "$onto" +then + test -z "$interactive_rebase" && interactive_rebase=implied +fi + if test -n "$interactive_rebase" then type=interactive @@ -397,7 +402,12 @@ then die "invalid upstream $upstream_name" upstream_arg="$upstream_name" else - test -z "$onto" && die "You must specify --onto when using --root" + if test -z "$onto" + then + empty_tree=`git hash-object -t tree /dev/null` + onto=`git commit-tree $empty_tree