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

Re: What's cooking in git.git (Mar 2010, #01; Wed, 03)

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 5, 2010, 00:49 UTC
Message-ID
<7vk4trlhim.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vmxynydac.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 31 quoted lines
>     $ git branch branch2                        <2>
>
> I take it that this is supposed to be "checkout -b branch2".
>
>     $ git reset --keep start                    <3>
>     ------------
>
>     <1> This commits your first edits in branch1.
>     <2> This creates branch2, but unfortunately it contains the previous
>     commit that you don't want in this branch.
>     <3> This removes the unwanted previous commit, but this keeps the
>     changes in your working tree.
>
> The above sequence is not very convincing.  After you edited the second
> time, you create branch2 and that is presumably because you realized that
> the change in the work tree belongs to a separate topic.  It would be a
> lot more natural to do this:
>
>     $ git tag start ;# we do not have to tag, but just to make the
>                        remainder of the illustration easier to read...
>     $ git checkout -b branch1
>     $ edit	    ;# do the work for the first topic
>     $ git commit    ;# and commit
>     $ edit          ;# start working more and then realize that the
>     		       change belongs to a separate topic, and the previous
>                        commit is unrelated to that new topic
>     $ git checkout -b branch2 start 
>     $ edit          ;# continue working
>     $ git commit    ;# and conclude it
>
> so the example makes the use of "reset --keep" look artificial.

Nah, what was I thinking. If I rephrase your side note <2> and <3> a little bit, everything makes sense. Perhaps like so:

    <2> In the ideal world, you could have realized that the earlier
    commit did not belong to the new topic when you created and switched
    to branch2 (i.e. "git checkout -b branch2 start"), but nobody is
    perfect.
    <3> But you can use "reset --keep" to remove the unwanted commit after
    you switched to "branch2".

And it becomes very clear that "reset --keep" is a sensible way to recover from this mistake. No need to do "read-tree -m -u" followed by "reset" anymore.

Do you think I finally understood what "reset --keep" is about?
Previous: Junio C HamanoNext: Jonathan Nieder
Message 8 of 38 in “What's cooking in git.git (Mar 2010, #01; Wed, 03)”
  1. Junio C HamanoMar 4, 2010
  2. Adam SimpkinsMar 4, 2010
  3. Björn GustavssonMar 4, 2010
  4. Junio C HamanoMar 4, 2010
  5. Tay Ray ChuanMar 4, 2010
  6. Junio C HamanoMar 4, 2010
  7. Junio C HamanoMar 4, 2010
  8. Junio C HamanoMar 5, 2010
  9. git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03))Jonathan Nieder, Mar 5, 2010
  10. Christian CouderMar 5, 2010
  11. Christian CouderMar 5, 2010
  12. Thomas RastMar 4, 2010
  13. Mark LodatoMar 5, 2010
  14. Mark LodatoMar 5, 2010
  15. Junio C HamanoMar 5, 2010
  16. Add tests for git format-patch --to and format.to config optionMiklos Vajna, Mar 6, 2010
  17. Junio C HamanoMar 6, 2010
  18. format-patch --to: overwrite format.to contents, don't append itMiklos Vajna, Mar 6, 2010
  19. Stephen BoydMar 7, 2010
  20. Miklos VajnaMar 7, 2010
  21. Junio C HamanoMar 7, 2010
  22. Stephen BoydMar 7, 2010
  23. Junio C HamanoMar 7, 2010
  24. 0/4 format-patch and send-email ignoring config settingsStephen Boyd, Mar 7, 2010
  25. 0/3 format-patch and send-email ignoring config settingsStephen Boyd, Mar 7, 2010
  26. 1/3 format-patch: use a string_list for headersStephen Boyd, Mar 7, 2010
  27. 2/3 format-patch: add --no-cc, --no-to, and --no-add-headersStephen Boyd, Mar 7, 2010
  28. 3/3 send-email: add --no-cc, --no-to, and --no-bccStephen Boyd, Mar 7, 2010
  29. Junio C HamanoMar 9, 2010
  30. 1/4 send-email: actually add bcc headersStephen Boyd, Mar 7, 2010
  31. Stephen BoydMar 7, 2010
  32. 2/4 format-patch: use a string_list for headersStephen Boyd, Mar 7, 2010
  33. Erik Faye-LundMar 7, 2010
  34. Stephen BoydMar 7, 2010
  35. Johannes SchindelinMar 7, 2010
  36. 3/4 format-patch: add --no-cc, --no-to, and --no-add-headersStephen Boyd, Mar 7, 2010
  37. 4/4 send-email: add --no-cc, --no-to, and --no-bccStephen Boyd, Mar 7, 2010
  38. Steven DrakeMar 10, 2010

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.