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

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>

Shawn O. Pearce committed Feb 5, 2007 at 15:21 UTC ea81fcc5762c56b13d1ad04d62b161d782c591f1
1 file changed +25 -2
Documentation/git-rebase.txt
+25 -2
@@ -114,6 +114,27 @@ would result in:
114
115 This is useful when topicB does not depend on topicA.
116
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 +
138 In case of conflict, git-rebase will stop at the first problematic commit
139 and leave conflict markers in the tree. You can use git diff to locate
140 the markers (<<<<<<) and make edits to resolve the conflict. For each
@@ -141,10 +162,12 @@ OPTIONS
162 <newbase>::
163 Starting point at which to create the new commits. If the
164 --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.
167
168 <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.
171
172 <branch>::
173 Working branch; defaults to HEAD.