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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 7, 2009, 20:05 UTC
Message-ID
<7vd477v17r.fsf@alter.siamese.dyndns.org>
In-Reply-To
<vpqvdkzwh3j.fsf@bauges.imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 26 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> +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
>> +
>> +----------------
>> +
>> +Again, updating A with this commit will fast-forward and your push will be
>> +accepted.
>
> Maybe add something about --force ? I don't like my wording very much,
> but a first try is this:
>
> Lastly, you can decide that the B shouldn't have existed, and delete
> it. This is to do with a lot of care, not only because it will discard
> the changes introduced in B, but also because if B has been pulled by
> someone else, he will have a view of history inconsistant with the
> original repository. This is done with the --force option.

To be consistent with the flow, I think you are discarding A in the example, not B. A is what somebody else pushed out before your failed attempt of pushing B, and --force will discard A, replacing its history with yours.

Of course, you also could decide that somebody else's change A is vastly superior than your crappy B, and you may decide to do "git reset --hard A" to get rid of your history locally; but you wouldn't be using "git push" after that. It is an equally valid outcome in the example situation and until you fetch to see what A is, you cannot decide.

So, probably the order to teach would be:
 - You can pull to merge, or pull --rebase to rebase; either way, you are
   trying to preserve both histories.  [I've written on this in the
   previous message]
 - But you may realize that the commit by the other (i.e. A) was an
   incorrect solution to the same problem you solved with your B.  You
   _could_ force the push to replace it with B in such a case.  You need
   to tell the person who pushed A (and everybody else who might have
   fetched A and built on top) to discard their history (and rebuild their
   work that was done on top of A on top of B). [This is yours with A <=> B]
 - Alternatively you may realize that the commit by the other (i.e. A) was
   much better solution to the same problem you tried to solve with your
   B.  In such a case, you can simply discard B in your history with "git
   reset --hard A" after fetching.  You wouldn't be pushing anything back
   in this case.

I actually do not think it is appropriate to teach --force in an example that involves more than one person (iow, in the context of the example in my patch). A lot better alternative in such a case is to "git merge -s ours A" and push the result out, which keeps the fast-forwardness for the person who did A, and others who pulled and built on top of A already.

So scratch your "lastly", replace it (and the second point in my list above) with:

 - You may realize that the commit by the other (i.e. A) was an incorrect
   solution to the same problem you solved with your B.  In such a case,
   do _not_ use --force to remove A from the public history.  Instead,
   resolve the merge (in the previous instruction) favoring your solution,
   e.g. "git pull -s ours", and push the result out.
Previous: Matthieu MoyNext: Matthieu Moy
Message 9 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.