git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Re: push: point to 'git pull' and 'git push --force' in case of non-fast forward

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 6, 2009, 21:32 UTC
Message-ID
<7vprb8d3xe.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20090806211610.GB12924@vidovic>
Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:
Show 16 quoted lines
>> +Note about fast-forwards
>> +------------------------
>> +
>> +When an update changes a branch (or more in general, a ref) that used to
>> +point at commit A to point at another commit B, it is called a
>> +fast-forward update if and only if B is a descendant of A.
>> +
>> +In a fast-forward update from A to B, the set of commits that the original
>> +commit A built on top of is a subset of the commits the new commit B
>> +builds on top of.  Hence, it does not lose any history.
>> +
>> +In contrast, a non-fast-forward update will lose history.
>
> I believe that this sentence a bit too much scaring for the beginner.
> There are two kinds of update (push and pull). We loose history only
> when pushing.

Three points that makes me think your suggested update is not appropriate are:

 (1) This patch is about git-push documentation;
 (2) The opposite of git-push is git-fetch, not git-pull; and a non
     fast-forward fetch does lose history if you start building on a
     now-rewound tip of the remote tracking branch; and
 (3) We _do_ want this section to be scary.  We want the readers to be
     fully aware of the implications before tempting them with the --force
     option.
Show 24 quoted lines
>> +Alternatively, you can rebase your change between X and B on top of A,
>> +with "git pull --rebase", and push the result back.  The rebase will
>> +create a new commit D that builds the change between X and B on top of
>> +A.
>> +
>> +----------------
>> +
>> +      B   D
>> +     /   /
>> + ---X---A
>> +
>> +----------------
>
> Wouldn't "git pull --rebase" loose B? Shouldn't we have this
>
>   ----------------
>   
>             D
>            /
>    ---X---A
>   
>   ----------------
>
> instead?

This makes B _loose_ (or, dangling), but does not _lose_ it. It is still reachable from the reflog.

We could choose to not draw it for simplicity, or we could annotate it like this for completeness (and to give a warm-fuzzy feeling to the reader that nothing is lost).

----------------
       branch@{1} (reachable from reflog)
             branch
      B      D
     /      /
 ---X------A
----------------

I don't know which is better. If we were printing in colours in the documentation, I would keep B but draw it in light gray.

Previous: Nicolas SebrechtNext: Matthieu Moy
Message 7 of 48 in “push: point to 'git pull' and 'git push --force' in case of non-fast forward”
  1. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 6, 2009
  2. Michael J GruberAug 6, 2009
  3. Matthieu MoyAug 7, 2009
  4. Michael J GruberAug 7, 2009
  5. Junio C HamanoAug 6, 2009
  6. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 6, 2009
  7. Junio C HamanoAug 6, 2009
  8. Matthieu MoyAug 7, 2009
  9. Junio C HamanoAug 7, 2009
  10. Matthieu MoyAug 7, 2009
  11. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 8, 2009
  12. Teemu LikonenAug 8, 2009
  13. Matthieu MoyAug 8, 2009
  14. Junio C HamanoAug 8, 2009
  15. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 8, 2009
  16. Matthieu MoyAug 9, 2009
  17. Junio C HamanoAug 9, 2009
  18. Matthieu MoyAug 10, 2009
  19. Junio C HamanoAug 10, 2009
  20. Matthieu MoyAug 10, 2009
  21. Nanako ShiraishiAug 11, 2009
  22. 0/4 make helpful messages optionalJeff King, Sep 6, 2009
  23. 1/4 push: fix english in non-fast-forward messageJeff King, Sep 6, 2009
  24. 2/4 push: re-flow non-fast-forward messageJeff King, Sep 6, 2009
  25. 3/4 push: make non-fast-forward help message configurableJeff King, Sep 6, 2009
  26. Junio C HamanoSep 6, 2009
  27. Jeff KingSep 6, 2009
  28. Junio C HamanoSep 6, 2009
  29. Jeff KingSep 6, 2009
  30. Junio C HamanoSep 6, 2009
  31. Sverre RabbelierSep 6, 2009
  32. Nanako ShiraishiSep 7, 2009
  33. Johannes SixtSep 7, 2009
  34. Mike HommeySep 7, 2009
  35. Jeff KingSep 7, 2009
  36. Matthieu MoySep 7, 2009
  37. Jeff KingSep 7, 2009
  38. Matthieu MoySep 7, 2009
  39. Uri OkrentSep 8, 2009
  40. Jeff KingSep 9, 2009
  41. 0/2 configurable advice messagesJeff King, Sep 9, 2009
  42. 1/2 push: make non-fast-forward help message configurableJeff King, Sep 9, 2009
  43. Junio C HamanoSep 9, 2009
  44. Jeff KingSep 9, 2009
  45. Junio C HamanoSep 9, 2009
  46. 2/2 status: make "how to stage" messages optionalJeff King, Sep 9, 2009
  47. 4/4 status: make "how to stage" messages optionalJeff King, Sep 6, 2009
  48. Matthieu MoySep 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.