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 <chris@arachsys.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
bc9e7dd41f
commit
df5df20c13
@ -31,7 +31,7 @@ SUBDIRECTORY_OK=Yes
|
||||
OPTIONS_KEEPDASHDASH=
|
||||
OPTIONS_SPEC="\
|
||||
git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
|
||||
git rebase [-i] [options] --onto <newbase> --root [<branch>]
|
||||
git rebase [-i] [options] [--onto <newbase>] --root [<branch>]
|
||||
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 </dev/null`
|
||||
squash_onto="$onto"
|
||||
fi
|
||||
unset upstream_name
|
||||
unset upstream
|
||||
upstream_arg=--root
|
||||
|
Reference in New Issue
Block a user