Skip to content

Commit af19f15

Browse files
authored
Merge pull request matplotlib#30984 from rcomer/interactive-rebase
DOC: update interactive rebase instructions
2 parents 4a2222c + e2c4572 commit af19f15

1 file changed

Lines changed: 70 additions & 58 deletions

File tree

doc/devel/development_workflow.rst

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ workflow is:
4040

4141
#. Start a new *feature branch* from ``upstream/main``::
4242

43-
git checkout -b my-feature upstream/main
43+
git checkout -b my-new-feature upstream/main
4444

4545
#. When you're done editing, e.g., ``lib/matplotlib/collections.py``, record your changes in Git::
4646

@@ -49,7 +49,7 @@ workflow is:
4949

5050
#. Push the changes to your GitHub fork::
5151

52-
git push -u origin my-feature
52+
git push -u origin my-new-feature
5353

5454

5555
.. _update-mirror-main:
@@ -250,15 +250,15 @@ If you notice you messed up after the rebase::
250250
If you forgot to make a backup branch::
251251

252252
# look at the reflog of the branch
253-
git reflog show cool-feature
253+
git reflog show my-new-feature
254254

255-
8630830 cool-feature@{0}: commit: BUG: io: close file handles immediately
256-
278dd2a cool-feature@{1}: rebase finished: refs/heads/my-feature-branch onto 11ee694744f2552d
257-
26aa21a cool-feature@{2}: commit: BUG: lib: make seek_gzip_factory not leak gzip obj
255+
8630830 my-new-feature@{0}: commit: BUG: io: close file handles immediately
256+
278dd2a my-new-feature@{1}: rebase finished: refs/heads/my-new-feature onto 11ee694744f2552d
257+
26aa21a my-new-feature@{2}: commit: BUG: lib: make seek_gzip_factory not leak gzip obj
258258
...
259259

260260
# reset the branch to where it was before the botched rebase
261-
git reset --hard cool-feature@{2}
261+
git reset --hard my-new-feature@{2}
262262

263263
.. _rewriting-commit-history:
264264

@@ -276,73 +276,85 @@ This can be done via *interactive rebasing*.
276276

277277
Suppose that the commit history looks like this::
278278

279-
git log --oneline
280-
eadc391 Fix some remaining bugs
281-
a815645 Modify it so that it works
282-
2dec1ac Fix a few bugs + disable
283-
13d7934 First implementation
284-
6ad92e5 * masked is now an instance of a new object, MaskedConstant
285-
29001ed Add pre-nep for a copule of structured_array_extensions.
279+
$ git log --oneline
280+
b7e99a8659 (HEAD -> my-new-feature) Fix some remaining bugs
281+
8a5de78b17 Modify it so that it works
282+
34448c69eb Fix a few bugs + disable
283+
9a5d1ca186 First implementation
284+
d1da6fbf0b (upstream/main) Merge pull request #30778 from timhoffm/decorator-tracebackhide
285+
6ad937ad83 Merge pull request #30838 from has2k1/fix-numpy-integer-markers
286286
...
287287

288-
and ``6ad92e5`` is the last commit in the ``cool-feature`` branch. Suppose we
288+
and ``b7e99a8659`` is the most recent commit in the ``my-new-feature`` branch. Suppose we
289289
want to make the following changes:
290290

291-
* Rewrite the commit message for ``13d7934`` to something more sensible.
292-
* Combine the commits ``2dec1ac``, ``a815645``, ``eadc391`` into a single one.
291+
* Rewrite the commit message for ``9a5d1ca186`` to something more specific.
292+
* Combine the commits ``34448c69eb``, ``8a5de78b17``, ``b7e99a8659`` into a single one.
293293

294294
We do as follows::
295295

296296
# make a backup of the current state
297297
git branch tmp HEAD
298298
# interactive rebase
299-
git rebase -i 6ad92e5
299+
git rebase -i d1da6fbf0b
300300

301301
This will open an editor with the following text in it::
302302

303-
pick 13d7934 First implementation
304-
pick 2dec1ac Fix a few bugs + disable
305-
pick a815645 Modify it so that it works
306-
pick eadc391 Fix some remaining bugs
303+
pick 9a5d1ca186 First implementation
304+
pick 34448c69eb Fix a few bugs + disable
305+
pick 8a5de78b17 Modify it so that it works
306+
pick b7e99a8659 Fix some remaining bugs
307307

308-
# Rebase 6ad92e5..eadc391 onto 6ad92e5
308+
# Rebase d1da6fbf0b..b7e99a8659 onto d1da6fbf0b (4 commands)
309309
#
310310
# Commands:
311-
# p, pick = use commit
312-
# r, reword = use commit, but edit the commit message
313-
# e, edit = use commit, but stop for amending
314-
# s, squash = use commit, but meld into previous commit
315-
# f, fixup = like "squash", but discard this commit's log message
311+
# p, pick <commit> = use commit
312+
# r, reword <commit> = use commit, but edit the commit message
313+
# e, edit <commit> = use commit, but stop for amending
314+
# s, squash <commit> = use commit, but meld into previous commit
315+
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
316+
# commit's log message, unless -C is used, in which case
317+
# keep only this commit's message; -c is same as -C but
318+
# opens the editor
319+
# x, exec <command> = run command (the rest of the line) using shell
320+
# b, break = stop here (continue rebase later with 'git rebase --continue')
321+
# d, drop <commit> = remove commit
322+
# l, label <label> = label current HEAD with a name
323+
# t, reset <label> = reset HEAD to a label
324+
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
325+
# create a merge commit using the original merge commit's
326+
# message (or the oneline, if no original merge commit was
327+
# specified); use -c <commit> to reword the commit message
328+
# u, update-ref <ref> = track a placeholder for the <ref> to be updated
329+
# to this position in the new commits. The <ref> is
330+
# updated at the end of the rebase
331+
#
332+
# These lines can be re-ordered; they are executed from top to bottom.
316333
#
317334
# If you remove a line here THAT COMMIT WILL BE LOST.
335+
#
318336
# However, if you remove everything, the rebase will be aborted.
319337
#
320338

321339
To achieve what we want, we will make the following changes to it::
322340

323-
r 13d7934 First implementation
324-
pick 2dec1ac Fix a few bugs + disable
325-
f a815645 Modify it so that it works
326-
f eadc391 Fix some remaining bugs
341+
r 9a5d1ca186 First implementation
342+
pick 34448c69eb Fix a few bugs + disable
343+
f 8a5de78b17 Modify it so that it works
344+
f b7e99a8659 Fix some remaining bugs
327345

328346
This means that (i) we want to edit the commit message for
329-
``13d7934``, and (ii) collapse the last three commits into one. Now we
347+
``9a5d1ca186``, and (ii) collapse the last three commits into one. Now we
330348
save and quit the editor.
331349

332350
Git will then immediately bring up an editor for editing the commit
333-
message. After revising it, we get the output::
334-
335-
[detached HEAD 721fc64] FOO: First implementation
336-
2 files changed, 199 insertions(+), 66 deletions(-)
337-
[detached HEAD 0f22701] Fix a few bugs + disable
338-
1 files changed, 79 insertions(+), 61 deletions(-)
339-
Successfully rebased and updated refs/heads/my-feature-branch.
351+
message. After revising it, the history looks like this::
340352

341-
and now, the history looks like this::
342-
343-
0f22701 Fix a few bugs + disable
344-
721fc64 ENH: Sophisticated feature
345-
6ad92e5 * masked is now an instance of a new object, MaskedConstant
353+
955f532b04 (HEAD -> my-new-feature) Fix a few bugs + disable
354+
5a2046b5a7 Add my coolest of features
355+
d1da6fbf0b (upstream/main) Merge pull request #30778 from timhoffm/decorator-tracebackhide
356+
6ad937ad83 Merge pull request #30838 from has2k1/fix-numpy-integer-markers
357+
...
346358

347359
If it went wrong, recovery is again possible as explained :ref:`above
348360
<recovering-from-mess-up>`.
@@ -359,14 +371,14 @@ Rebase onto ``upstream/main``
359371

360372
Let's say you thought of some work you'd like to do. You
361373
:ref:`update-mirror-main` and :ref:`make-feature-branch` called
362-
``cool-feature``. At this stage, ``main`` is at some commit, let's call it E.
363-
Now you make some new commits on your ``cool-feature`` branch, let's call them
374+
``my-new-feature``. At this stage, ``main`` is at some commit, let's call it E.
375+
Now you make some new commits on your ``my-new-feature`` branch, let's call them
364376
A, B, C. Maybe your changes take a while, or you come back to them after a
365377
while. In the meantime, ``main`` has progressed from commit E to commit (say) G:
366378

367379
.. code-block:: none
368380
369-
A---B---C cool-feature
381+
A---B---C my-new-feature
370382
/
371383
D---E---F---G main
372384
@@ -384,7 +396,7 @@ rebase, your history will look like this:
384396

385397
.. code-block:: none
386398
387-
A'--B'--C' cool-feature
399+
A'--B'--C' my-new-feature
388400
/
389401
D---E---F---G main
390402
@@ -397,13 +409,13 @@ To do a rebase on ``upstream/main``::
397409
# Fetch changes from upstream/main
398410
git fetch upstream
399411
# go to the feature branch
400-
git checkout cool-feature
412+
git checkout my-new-feature
401413
# make a backup in case you mess up
402-
git branch tmp cool-feature
403-
# rebase cool-feature onto main
404-
git rebase --onto upstream/main upstream/main cool-feature
414+
git branch tmp my-new-feature
415+
# rebase my-new-feature onto main
416+
git rebase --onto upstream/main upstream/main my-new-feature
405417

406-
In this situation, where you are already on branch ``cool-feature``, the last
418+
In this situation, where you are already on branch ``my-new-feature``, the last
407419
command can be written more succinctly as::
408420

409421
git rebase upstream/main
@@ -442,13 +454,13 @@ a git history that looks something like
442454

443455
.. code-block:: none
444456
445-
A'--E cool-feature
457+
A'--E my-new-feature
446458
/
447-
D---A---B---C origin/cool-feature
459+
D---A---B---C origin/my-new-feature
448460
449461
where you have pushed the commits ``A,B,C`` to your fork on GitHub (under the
450462
remote name *origin*) but now have the commits ``A'`` and ``E`` on your local
451-
branch *cool-feature*. If you try to push the new commits to GitHub, it will
463+
branch *my-new-feature*. If you try to push the new commits to GitHub, it will
452464
fail and show an error that looks like ::
453465

454466
$ git push
@@ -466,7 +478,7 @@ longer be referenced by any branch and they would be discarded:
466478

467479
.. code-block:: none
468480
469-
D---A'---E cool-feature, origin/cool-feature
481+
D---A'---E my-new-feature, origin/my-new-feature
470482
471483
By default ``git push`` helpfully tries to protect you from accidentally
472484
discarding commits by rejecting the push to the remote. When this happens,

0 commit comments

Comments
 (0)