* [PATCH] git-rebase: make 'rebase HEAD branch' works as expected.
@ 2007-03-22 9:54 Junio C Hamano
0 siblings, 0 replies; only message in thread
From: Junio C Hamano @ 2007-03-22 9:54 UTC (permalink / raw
To: git
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
first 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 onto HEAD with this:
$ git rebase HEAD master
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>
---
* By the way, if you change the contents of the commit at the
same time (i.e. tree(B) and tree(B') are different in the
example), then rebase would say B and B' conflict. In such a
case, you can do:
$ git rebase --onto HEAD master~3 master
This is not something new, but I thought it would be good to
mention it.
git-rebase.sh | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index b51d19d..aadd580 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -265,6 +265,10 @@ upstream_name="$1"
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
die "invalid upstream $upstream_name"
+# Make sure the branch to rebase onto is valid.
+onto_name=${newbase-"$upstream_name"}
+onto=$(git-rev-parse --verify "${onto_name}^0") || exit
+
# If a hook exists, give it a chance to interrupt
if test -x "$GIT_DIR/hooks/pre-rebase"
then
@@ -291,10 +295,6 @@ case "$#" in
esac
branch=$(git-rev-parse --verify "${branch_name}^0") || exit
-# Make sure the branch to rebase onto is valid.
-onto_name=${newbase-"$upstream_name"}
-onto=$(git-rev-parse --verify "${onto_name}^0") || exit
-
# Now we are rebasing commits $upstream..$branch on top of $onto
# Check if we are already based on $onto, but this should be
--
1.5.1.rc1.635.gd0664
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-03-22 9:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-22 9:54 [PATCH] git-rebase: make 'rebase HEAD branch' works as expected Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).