Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58ac02d

Browse files
committed
DOC: put re-writing your own commits above rebasing on main
1 parent d905955 commit 58ac02d

File tree

1 file changed

+72
-73
lines changed

1 file changed

+72
-73
lines changed

doc/devel/development_workflow.rst

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -201,79 +201,6 @@ If you forgot to make a backup branch::
201201
# reset the branch to where it was before the botched rebase
202202
git reset --hard cool-feature@{2}
203203

204-
205-
.. _rebase-on-main:
206-
207-
Rebasing on ``upstream/main``
208-
-----------------------------
209-
210-
Let's say you thought of some work you'd like to do. You
211-
:ref:`update-mirror-main` and :ref:`make-feature-branch` called
212-
``cool-feature``. At this stage, ``main`` is at some commit, let's call it E.
213-
Now you make some new commits on your ``cool-feature`` branch, let's call them
214-
A, B, C. Maybe your changes take a while, or you come back to them after a
215-
while. In the meantime, ``main`` has progressed from commit E to commit (say) G:
216-
217-
.. code-block:: none
218-
219-
A---B---C cool-feature
220-
/
221-
D---E---F---G main
222-
223-
At this stage you consider merging ``main`` into your feature branch, and you
224-
remember that this here page sternly advises you not to do that, because the
225-
history will get messy. Most of the time you can just ask for a review, and not
226-
worry that ``main`` has got a little ahead. But sometimes, the changes in
227-
``main`` might affect your changes, and you need to harmonize them. In this
228-
situation you may prefer to do a rebase.
229-
230-
``rebase`` takes your changes (A, B, C) and replays them as if they had been
231-
made to the current state of ``main``. In other words, in this case, it takes
232-
the changes represented by A, B, C and replays them on top of G. After the
233-
rebase, your history will look like this:
234-
235-
.. code-block:: none
236-
237-
A'--B'--C' cool-feature
238-
/
239-
D---E---F---G main
240-
241-
See `rebase without tears`_ for more detail.
242-
243-
.. _rebase without tears: https://matthew-brett.github.io/pydagogue/rebase_without_tears.html
244-
245-
To do a rebase on ``upstream/main``::
246-
247-
# Fetch changes from upstream/main
248-
git fetch upstream
249-
# go to the feature branch
250-
git checkout cool-feature
251-
# make a backup in case you mess up
252-
git branch tmp cool-feature
253-
# rebase cool-feature onto main
254-
git rebase --onto upstream/main upstream/main cool-feature
255-
256-
In this situation, where you are already on branch ``cool-feature``, the last
257-
command can be written more succinctly as::
258-
259-
git rebase upstream/main
260-
261-
When all looks good you can delete your backup branch::
262-
263-
git branch -D tmp
264-
265-
If it doesn't look good you may need to have a look at
266-
:ref:`recovering-from-mess-up`.
267-
268-
If you have made changes to files that have also changed in ``main``, this may
269-
generate merge conflicts that you need to resolve - see the `git rebase`_ man
270-
page for some instructions at the end of the "Description" section. There is
271-
some related help on merging in the git user manual - see `resolving a merge`_.
272-
273-
.. _git rebase: https://git-scm.com/docs/git-rebase
274-
.. _resolving a merge: https://schacon.github.io/git/user-manual.html#resolving-a-merge
275-
276-
277204
.. _rewriting-commit-history:
278205

279206
Rewriting commit history
@@ -360,3 +287,75 @@ and the history looks now like this::
360287

361288
If it went wrong, recovery is again possible as explained :ref:`above
362289
<recovering-from-mess-up>`.
290+
291+
292+
.. _rebase-on-main:
293+
294+
Rebasing on ``upstream/main``
295+
-----------------------------
296+
297+
Let's say you thought of some work you'd like to do. You
298+
:ref:`update-mirror-main` and :ref:`make-feature-branch` called
299+
``cool-feature``. At this stage, ``main`` is at some commit, let's call it E.
300+
Now you make some new commits on your ``cool-feature`` branch, let's call them
301+
A, B, C. Maybe your changes take a while, or you come back to them after a
302+
while. In the meantime, ``main`` has progressed from commit E to commit (say) G:
303+
304+
.. code-block:: none
305+
306+
A---B---C cool-feature
307+
/
308+
D---E---F---G main
309+
310+
At this stage you consider merging ``main`` into your feature branch, and you
311+
remember that this here page sternly advises you not to do that, because the
312+
history will get messy. Most of the time you can just ask for a review, and not
313+
worry that ``main`` has got a little ahead. But sometimes, the changes in
314+
``main`` might affect your changes, and you need to harmonize them. In this
315+
situation you may prefer to do a rebase.
316+
317+
``rebase`` takes your changes (A, B, C) and replays them as if they had been
318+
made to the current state of ``main``. In other words, in this case, it takes
319+
the changes represented by A, B, C and replays them on top of G. After the
320+
rebase, your history will look like this:
321+
322+
.. code-block:: none
323+
324+
A'--B'--C' cool-feature
325+
/
326+
D---E---F---G main
327+
328+
See `rebase without tears`_ for more detail.
329+
330+
.. _rebase without tears: https://matthew-brett.github.io/pydagogue/rebase_without_tears.html
331+
332+
To do a rebase on ``upstream/main``::
333+
334+
# Fetch changes from upstream/main
335+
git fetch upstream
336+
# go to the feature branch
337+
git checkout cool-feature
338+
# make a backup in case you mess up
339+
git branch tmp cool-feature
340+
# rebase cool-feature onto main
341+
git rebase --onto upstream/main upstream/main cool-feature
342+
343+
In this situation, where you are already on branch ``cool-feature``, the last
344+
command can be written more succinctly as::
345+
346+
git rebase upstream/main
347+
348+
When all looks good you can delete your backup branch::
349+
350+
git branch -D tmp
351+
352+
If it doesn't look good you may need to have a look at
353+
:ref:`recovering-from-mess-up`.
354+
355+
If you have made changes to files that have also changed in ``main``, this may
356+
generate merge conflicts that you need to resolve - see the `git rebase`_ man
357+
page for some instructions at the end of the "Description" section. There is
358+
some related help on merging in the git user manual - see `resolving a merge`_.
359+
360+
.. _git rebase: https://git-scm.com/docs/git-rebase
361+
.. _resolving a merge: https://schacon.github.io/git/user-manual.html#resolving-a-merge

0 commit comments

Comments
 (0)