Skip to content

Commit 310d188

Browse files
committed
Merge branch 'tr/workflow-doc'
* tr/workflow-doc: Documentation: add manpage about workflows Documentation: Refer to git-rebase(1) to warn against rewriting Documentation: new upstream rebase recovery section in git-rebase
2 parents adcb2e0 + f948dd8 commit 310d188

File tree

6 files changed

+500
-8
lines changed

6 files changed

+500
-8
lines changed

Documentation/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt githooks.txt \
66
gitrepository-layout.txt
77
MAN7_TXT=gitcli.txt gittutorial.txt gittutorial-2.txt \
88
gitcvs-migration.txt gitcore-tutorial.txt gitglossary.txt \
9-
gitdiffcore.txt
9+
gitdiffcore.txt gitworkflows.txt
1010

1111
MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
1212
MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))

Documentation/git-commit.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ It is a rough equivalent for:
145145
------
146146
but can be used to amend a merge commit.
147147
--
148+
+
149+
You should understand the implications of rewriting history if you
150+
amend a commit that has already been published. (See the "RECOVERING
151+
FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
148152

149153
-i::
150154
--include::

Documentation/git-filter-branch.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ the objects and will not converge with the original branch. You will not
3636
be able to easily push and distribute the rewritten branch on top of the
3737
original branch. Please do not use this command if you do not know the
3838
full implications, and avoid using it anyway, if a simple single commit
39-
would suffice to fix your problem.
39+
would suffice to fix your problem. (See the "RECOVERING FROM UPSTREAM
40+
REBASE" section in linkgit:git-rebase[1] for further information about
41+
rewriting published history.)
4042

4143
Always verify that the rewritten version is correct: The original refs,
4244
if different from the rewritten ones, will be stored in the namespace

Documentation/git-rebase.txt

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,10 @@ include::merge-strategies.txt[]
259259

260260
NOTES
261261
-----
262-
When you rebase a branch, you are changing its history in a way that
263-
will cause problems for anyone who already has a copy of the branch
264-
in their repository and tries to pull updates from you. You should
265-
understand the implications of using 'git-rebase' on a repository that
266-
you share.
262+
263+
You should understand the implications of using 'git-rebase' on a
264+
repository that you share. See also RECOVERING FROM UPSTREAM REBASE
265+
below.
267266

268267
When the git-rebase command is run, it will first execute a "pre-rebase"
269268
hook if one exists. You can use this hook to do sanity checks and
@@ -398,6 +397,127 @@ consistent (they compile, pass the testsuite, etc.) you should use
398397
after each commit, test, and amend the commit if fixes are necessary.
399398

400399

400+
RECOVERING FROM UPSTREAM REBASE
401+
-------------------------------
402+
403+
Rebasing (or any other form of rewriting) a branch that others have
404+
based work on is a bad idea: anyone downstream of it is forced to
405+
manually fix their history. This section explains how to do the fix
406+
from the downstream's point of view. The real fix, however, would be
407+
to avoid rebasing the upstream in the first place.
408+
409+
To illustrate, suppose you are in a situation where someone develops a
410+
'subsystem' branch, and you are working on a 'topic' that is dependent
411+
on this 'subsystem'. You might end up with a history like the
412+
following:
413+
414+
------------
415+
o---o---o---o---o---o---o---o---o master
416+
\
417+
o---o---o---o---o subsystem
418+
\
419+
*---*---* topic
420+
------------
421+
422+
If 'subsystem' is rebased against 'master', the following happens:
423+
424+
------------
425+
o---o---o---o---o---o---o---o master
426+
\ \
427+
o---o---o---o---o o'--o'--o'--o'--o' subsystem
428+
\
429+
*---*---* topic
430+
------------
431+
432+
If you now continue development as usual, and eventually merge 'topic'
433+
to 'subsystem', the commits from 'subsystem' will remain duplicated forever:
434+
435+
------------
436+
o---o---o---o---o---o---o---o master
437+
\ \
438+
o---o---o---o---o o'--o'--o'--o'--o'--M subsystem
439+
\ /
440+
*---*---*-..........-*--* topic
441+
------------
442+
443+
Such duplicates are generally frowned upon because they clutter up
444+
history, making it harder to follow. To clean things up, you need to
445+
transplant the commits on 'topic' to the new 'subsystem' tip, i.e.,
446+
rebase 'topic'. This becomes a ripple effect: anyone downstream from
447+
'topic' is forced to rebase too, and so on!
448+
449+
There are two kinds of fixes, discussed in the following subsections:
450+
451+
Easy case: The changes are literally the same.::
452+
453+
This happens if the 'subsystem' rebase was a simple rebase and
454+
had no conflicts.
455+
456+
Hard case: The changes are not the same.::
457+
458+
This happens if the 'subsystem' rebase had conflicts, or used
459+
`\--interactive` to omit, edit, or squash commits; or if the
460+
upstream used one of `commit \--amend`, `reset`, or
461+
`filter-branch`.
462+
463+
464+
The easy case
465+
~~~~~~~~~~~~~
466+
467+
Only works if the changes (patch IDs based on the diff contents) on
468+
'subsystem' are literally the same before and after the rebase
469+
'subsystem' did.
470+
471+
In that case, the fix is easy because 'git-rebase' knows to skip
472+
changes that are already present in the new upstream. So if you say
473+
(assuming you're on 'topic')
474+
------------
475+
$ git rebase subsystem
476+
------------
477+
you will end up with the fixed history
478+
------------
479+
o---o---o---o---o---o---o---o master
480+
\
481+
o'--o'--o'--o'--o' subsystem
482+
\
483+
*---*---* topic
484+
------------
485+
486+
487+
The hard case
488+
~~~~~~~~~~~~~
489+
490+
Things get more complicated if the 'subsystem' changes do not exactly
491+
correspond to the ones before the rebase.
492+
493+
NOTE: While an "easy case recovery" sometimes appears to be successful
494+
even in the hard case, it may have unintended consequences. For
495+
example, a commit that was removed via `git rebase
496+
\--interactive` will be **resurrected**!
497+
498+
The idea is to manually tell 'git-rebase' "where the old 'subsystem'
499+
ended and your 'topic' began", that is, what the old merge-base
500+
between them was. You will have to find a way to name the last commit
501+
of the old 'subsystem', for example:
502+
503+
* With the 'subsystem' reflog: after 'git-fetch', the old tip of
504+
'subsystem' is at `subsystem@\{1}`. Subsequent fetches will
505+
increase the number. (See linkgit:git-reflog[1].)
506+
507+
* Relative to the tip of 'topic': knowing that your 'topic' has three
508+
commits, the old tip of 'subsystem' must be `topic~3`.
509+
510+
You can then transplant the old `subsystem..topic` to the new tip by
511+
saying (for the reflog case, and assuming you are on 'topic' already):
512+
------------
513+
$ git rebase --onto subsystem subsystem@{1}
514+
------------
515+
516+
The ripple effect of a "hard case" recovery is especially bad:
517+
'everyone' downstream from 'topic' will now have to perform a "hard
518+
case" recovery too!
519+
520+
401521
Authors
402522
------
403523
Written by Junio C Hamano <gitster@pobox.com> and

Documentation/git-reset.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ $ git reset --hard HEAD~3 <1>
8282
+
8383
<1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad
8484
and you do not want to ever see them again. Do *not* do this if
85-
you have already given these commits to somebody else.
85+
you have already given these commits to somebody else. (See the
86+
"RECOVERING FROM UPSTREAM REBASE" section in linkgit:git-rebase[1] for
87+
the implications of doing so.)
8688

8789
Undo a commit, making it a topic branch::
8890
+

0 commit comments

Comments
 (0)