{"thread":{"id":"7352","subject":"[PATCH] git-rebase: make 'rebase HEAD branch' works as expected.","startedAt":"2007-03-22T09:54:59Z","lastAt":"2007-03-22T09:54:59Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37733","messageId":"7vzm65txfw.fsf@assigned-by-dhcp.cox.net","threadId":"7352","inReplyTo":null,"subject":"[PATCH] git-rebase: make 'rebase HEAD branch' works as expected.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-22T09:54:59Z","receivedAt":"2007-03-22T09:54:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When you want to amend the commit message of 3 commits before\nthe tip of the current branch, say 'master',\n\n\tA--B--C--D--E(master)\n\nit is sometimes handy to make your head detached at that commit\nfirst with:\n\n\t$ git checkout HEAD~3 ;# check out B\n\t$ git commit --amend ;# without modifying contents...\n\nto create\n\n          .B'(HEAD)\n         /\n\tA--B--C--D--E(master)\n\nand then rebase master onto HEAD with this:\n\n\t$ git rebase HEAD master\n\nHowever, the current code interprets HEAD _after_ it switches to\nthe branch 'master', which means the rebase will not do\nanything.  You have to say something unwieldly like this instead:\n\n\t$ git rebase $(git rev-parse HEAD) master\n\nThis fixes it by expanding the $onto commit name before\nswitching to the target branch.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n * By the way, if you change the contents of the commit at the\n   same time (i.e. tree(B) and tree(B') are different in the\n   example), then rebase would say B and B' conflict.  In such a\n   case, you can do:\n\n\t$ git rebase --onto HEAD master~3 master\n\n   This is not something new, but I thought it would be good to\n   mention it.\n\n git-rebase.sh |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b51d19d..aadd580 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -265,6 +265,10 @@ upstream_name=\"$1\"\n upstream=`git rev-parse --verify \"${upstream_name}^0\"` ||\n     die \"invalid upstream $upstream_name\"\n \n+# Make sure the branch to rebase onto is valid.\n+onto_name=${newbase-\"$upstream_name\"}\n+onto=$(git-rev-parse --verify \"${onto_name}^0\") || exit\n+\n # If a hook exists, give it a chance to interrupt\n if test -x \"$GIT_DIR/hooks/pre-rebase\"\n then\n@@ -291,10 +295,6 @@ case \"$#\" in\n esac\n branch=$(git-rev-parse --verify \"${branch_name}^0\") || exit\n \n-# Make sure the branch to rebase onto is valid.\n-onto_name=${newbase-\"$upstream_name\"}\n-onto=$(git-rev-parse --verify \"${onto_name}^0\") || exit\n-\n # Now we are rebasing commits $upstream..$branch on top of $onto\n \n # Check if we are already based on $onto, but this should be\n-- \n1.5.1.rc1.635.gd0664\n"}]}