3 # Copyright (c) 2005 Junio C Hamano.
6 USAGE
='[--onto <newbase>] <upstream> [<branch>]'
7 LONG_USAGE
='git-rebase replaces <branch> with a new branch of the
8 same name. When the --onto option is provided the new branch starts
9 out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
10 It then attempts to create a new commit for each commit from the original
11 <branch> that does not exist in the <upstream> branch.
13 It is possible that a merge failure will prevent this process from being
14 completely automatic. You will have to resolve any such merge failure
15 and run git-rebase --continue. If you can not resolve the merge failure,
16 running git-rebase --abort will restore the original <branch> and remove
17 the working files found in the .dotest directory.
19 Note that if <branch> is not specified on the command line, the
20 currently checked out branch is used. You must be in the top
21 directory of your project to start (or continue) a rebase.
23 Example: git-rebase master~1 topic
25 A---B---C topic A'\''--B'\''--C'\'' topic
27 D---E---F---G master D---E---F---G master
32 while case "$#" in 0) break ;; esac
36 diff=$
(git-diff-files
)
38 ?
*) echo "You must edit all merge conflicts and then"
39 echo "mark them as resolved using git update-index"
43 git am
--resolved --3way
47 [ -d .dotest
] || die
"No rebase in progress?"
48 git
reset --hard ORIG_HEAD
53 test 2 -le "$#" || usage
67 # Make sure we do not have .dotest
73 It seems that I cannot create a .dotest directory, and I wonder if you
74 are in the middle of patch application or another rebase. If that is not
75 the case, please rm -fr .dotest and run me again. I am stopping in case
76 you still have something valuable there.'
80 # The tree must be really really clean.
81 git-update-index
--refresh ||
exit
82 diff=$
(git-diff-index
--cached --name-status -r HEAD
)
89 # The upstream head must be given. Make sure it is valid.
91 upstream
=`git rev-parse --verify "${upstream_name}^0"` ||
92 die
"invalid upstream $upstream_name"
94 # If a hook exists, give it a chance to interrupt
95 if test -x "$GIT_DIR/hooks/pre-rebase"
97 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
{
98 echo >&2 "The pre-rebase hook refused to rebase."
103 # If the branch to rebase is given, first switch to it.
107 git-checkout
"$2" || usage
110 branch_name
=`git symbolic-ref HEAD` || die
"No current branch"
111 branch_name
=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'`
114 branch
=$
(git-rev-parse
--verify "${branch_name}^0") ||
exit
116 # Make sure the branch to rebase onto is valid.
117 onto_name
=${newbase-"$upstream_name"}
118 onto
=$
(git-rev-parse
--verify "${onto_name}^0") ||
exit
120 # Now we are rebasing commits $upstream..$branch on top of $onto
122 # Check if we are already based on $onto, but this should be
123 # done only when upstream and onto are the same.
124 if test "$upstream" = "$onto"
126 mb
=$
(git-merge-base
"$onto" "$branch")
127 if test "$mb" = "$onto"
129 echo >&2 "Current branch $branch_name is up to date."
134 # Rewind the head to "$onto"; this saves our current head in ORIG_HEAD.
135 git-reset
--hard "$onto"
137 # If the $onto is a proper descendant of the tip of the branch, then
138 # we just fast forwarded.
139 if test "$mb" = "$onto"
141 echo >&2 "Fast-forwarded $branch to $newbase."
145 git-format-patch
-k --stdout --full-index "$upstream" ORIG_HEAD |
146 git am
--binary -3 -k