@matheusbsbs / matheus-bagliano / commits / a1bf91e081
Fork 0

git-rebase: make 'rebase HEAD branch' work as expected.

When you want to amend the commit message of 3 commits before the tip of the current branch, say 'master', A--B--C--D--E(master) it is sometimes handy to make your head detached at that commit with: $ git checkout HEAD~3 ;# check out B $ git commit --amend ;# without modifying contents... to create: .B'(HEAD) / A--B--C--D--E(master) and then rebase 'master' branch onto HEAD with this: $ git rebase HEAD master to result in: .B'-C'-D'-E(master=HEAD) / A--B--C--D--E However, the current code interprets HEAD after it switches to the branch 'master', which means the rebase will not do anything. You have to say something unwieldly like this instead: $ git rebase $(git rev-parse HEAD) master This fixes it by expanding the $onto commit name before switching to the target branch. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 22, 2007 at 02:54 UTC a1bf91e081de236af34bf8acd484881ce146fc93
1 file changed +4 -4
git-rebase.sh
+4 -4
@@ -265,6 +265,10 @@ upstream_name="$1"
265 upstream=`git rev-parse --verify "${upstream_name}^0"` ||
266 die "invalid upstream $upstream_name"
267
268 +# Make sure the branch to rebase onto is valid.
269 +onto_name=${newbase-"$upstream_name"}
270 +onto=$(git-rev-parse --verify "${onto_name}^0") || exit
271 +
272 # If a hook exists, give it a chance to interrupt
273 if test -x "$GIT_DIR/hooks/pre-rebase"
274 then
@@ -291,10 +295,6 @@ case "$#" in
295 esac
296 branch=$(git-rev-parse --verify "${branch_name}^0") || exit
297
294 -# Make sure the branch to rebase onto is valid.
295 -onto_name=${newbase-"$upstream_name"}
296 -onto=$(git-rev-parse --verify "${onto_name}^0") || exit
297 -
298 # Now we are rebasing commits $upstream..$branch on top of $onto
299
300 # Check if we are already based on $onto, but this should be