Skip to content

Commit ea81fcc

Browse files
spearceJunio C Hamano
authored andcommitted
Show an example of deleting commits with git-rebase.
This particular use of git-rebase to remove a single commit or a range of commits from the history of a branch recently came up on the mailing list. Documenting the example should help other users arrive at the same solution on their own. It also was not obvious to the newcomer that git-rebase is able to accept any commit for --onto <newbase> and <upstream>. We should at least minimally document this, as much of the language in git-rebase's manpage refers to 'branch' rather than 'committish'. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 69057cf commit ea81fcc

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Documentation/git-rebase.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ would result in:
114114

115115
This is useful when topicB does not depend on topicA.
116116

117+
A range of commits could also be removed with rebase. If we have
118+
the following situation:
119+
120+
------------
121+
E---F---G---H---I---J topicA
122+
------------
123+
124+
then the command
125+
126+
git-rebase --onto topicA~5 topicA~2 topicA
127+
128+
would result in the removal of commits F and G:
129+
130+
------------
131+
E---H'---I'---J' topicA
132+
------------
133+
134+
This is useful if F and G were flawed in some way, or should not be
135+
part of topicA. Note that the argument to --onto and the <upstream>
136+
parameter can be any valid commit-ish.
137+
117138
In case of conflict, git-rebase will stop at the first problematic commit
118139
and leave conflict markers in the tree. You can use git diff to locate
119140
the markers (<<<<<<) and make edits to resolve the conflict. For each
@@ -141,10 +162,12 @@ OPTIONS
141162
<newbase>::
142163
Starting point at which to create the new commits. If the
143164
--onto option is not specified, the starting point is
144-
<upstream>.
165+
<upstream>. May be any valid commit, and not just an
166+
existing branch name.
145167

146168
<upstream>::
147-
Upstream branch to compare against.
169+
Upstream branch to compare against. May be any valid commit,
170+
not just an existing branch name.
148171

149172
<branch>::
150173
Working branch; defaults to HEAD.

0 commit comments

Comments
 (0)