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

Re: An alternate model for preparing partial commits

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 28, 2008, 21:53 UTC
Message-ID
<7vprq1kz0d.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080628085359.GA29619@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> Actually, I oversimplified a little bit in my "buckets" description.
> Stash actually stashes two things: the current index and the current
> worktree. So in that sense, it is not just another bucket as I
> described. For the purposes of the workflow we're discussing, I think
> that is how we want it to function. But the implementation will be a bit
> trickier than it might otherwise be because of this. I just didn't want
> to have to introduce another, slightly different type of stash.

You do *not* have to use stash that has different index and work tree components and then your buckets description makes sense.

The index is to hold good changes verified to be fine to make commits, the work tree is to test and verify outstanding changes, and the stash is to hold the remainder (i.e. further changes that does not belong to what you are currently looking at in your work tree).

When your workflow is to "verify and immediately commit", then the need for buckets to your particular workflow can degenerate to a one that does not need the index. That is essentially Robert's workflow (but it does not mean it is the only valid one).

What I do these days is this:
 * Fork a new topic from the commit I pushed out the last time to the
   public ("git checkout -b jc/topic ko/master").
 * Think, hack, commit, think, hack, commit, lather, rinse, repeat.
 * Make sure everything is worthy for the final state.  There can be (and
   need to be to use the current set of tools) some uncommitted changes.
   Make a stash, so that the work tree component records the final tree,
   and mentally name it the "commit goal".
 * I have never grew comfortable operating "edit" insn in "rebase -i", so
   the workflow from this point does not use it.  Instead, I detech the
   HEAD to the root of the series ("git checkout ko/master^0") at this
   point.  Now, none of my change is in the work tree.
 * Repeat the following:
   * Recreate the work tree state for the next round to be built on HEAD
     and make a commit, after verifying what I have in the commit is good.
     Examples of the tools at my disposal are:
     * "cherry-pick jc/topic~$N" to get the necessary changes from my
       earlier "snapshots", which can possibly be followed by a "git
       commit --amend".  This "going forward" is easiest especially in the
       early part of the sequence.
       "format-patch --stdout jc/topic~$N..jc/topic~$M | git am" is a
       slight variant of the above when I already had a good logical
       sequence (someday we probably will have "cherry-pick A..B").
     * "read-tree -m -u stash" to read the final state of the tree,
       selectively _remove_ the parts I do not want in this round, and
       make a commit ("git add -i && git commit && git reset --hard").
       This "going backward" is easier near the end of the sequence than
       other method that goes forward.
   * If I find some issues to be fixed in the state that was stashed
     (which I earlier thought was perfect) during the above:
    * "read-tree -m -u stash" to read the (previous) final state, fix it
      up, "stash drop" and "stash save" to update our "commit goal".
   The above is repeated until "git diff HEAD stash" does not have
   anything I need in the final series.
   The lower-level "read-tree -m -u" probably can be replaced with "stash
   apply" in real life, but I tend to try to ask for the final tree
   explicitly, because there is no reason to perform three-way merge dance
   "stash apply" does for these steps.
 * Final re-review:
   * "git diff jc/topic HEAD" to see if I did not miss anything (and review
     the "oops, the earlier commit goal was faulty" fixes).
   * "git log --reverse -p ko/master.." to see the final shape of the
     series.
 * "git branch -f jc/topic" to finish it off.

The commits from the session are merely convenient snapshot points that I can use during the clean-up phase for series of cherry-picks to prepare bulk of each of the logical change in the final series. If somebody subscribes to a dogma not to make commits of unproven changes, that is fine, and such a person may not have any commits during "think, hack, lather, rinse, repeat" phase, and that is fine. But fortunately I don't.

Previous: Jeff KingNext: Johannes Schindelin
Message 30 of 57 in “An alternate model for preparing partial commits”
  1. Robert AndersonJun 27, 2008
  2. Björn SteinbrinkJun 27, 2008
  3. stash: introduce 'stash save --keep-index' optionSZEDER Gábor, Jun 27, 2008
  4. Junio C HamanoJun 27, 2008
  5. Robert AndersonJun 27, 2008
  6. Björn SteinbrinkJun 27, 2008
  7. Robert AndersonJun 27, 2008
  8. Johannes SixtJun 27, 2008
  9. Robert AndersonJun 27, 2008
  10. Petr BaudisJun 27, 2008
  11. Robert AndersonJun 27, 2008
  12. Johannes SchindelinJun 27, 2008
  13. Miklos VajnaJun 27, 2008
  14. Robert AndersonJun 27, 2008
  15. Johannes SchindelinJun 27, 2008
  16. Robert AndersonJun 27, 2008
  17. Dana HowJun 27, 2008
  18. Stephen SinclairJun 27, 2008
  19. David JeskeJun 27, 2008
  20. David JeskeAug 13, 2016
  21. Wincent ColaiutaJun 28, 2008
  22. Dmitry PotapovJun 28, 2008
  23. Robert AndersonJun 28, 2008
  24. Dmitry PotapovJun 28, 2008
  25. Junio C HamanoJun 27, 2008
  26. Robert AndersonJun 27, 2008
  27. Jeff KingJun 28, 2008
  28. Robert AndersonJun 28, 2008
  29. Jeff KingJun 28, 2008
  30. Junio C HamanoJun 28, 2008
  31. Johannes SchindelinJun 28, 2008
  32. Jeff KingJul 8, 2008
  33. David JeskeJun 27, 2008
  34. Jakub NarebskiJun 27, 2008
  35. David JeskeJun 27, 2008
  36. David JeskeAug 13, 2016
  37. David JeskeAug 13, 2016
  38. Robert AndersonJun 27, 2008
  39. Robert AndersonJun 27, 2008
  40. Junio C HamanoJun 27, 2008
  41. Robert AndersonJun 28, 2008
  42. Dmitry PotapovJun 28, 2008
  43. Robert AndersonJun 28, 2008
  44. Stephen SinclairJun 28, 2008
  45. Robert AndersonJun 28, 2008
  46. Robert AndersonJun 28, 2008
  47. Jakub NarebskiJun 28, 2008
  48. Robert AndersonJun 28, 2008
  49. David JeskeJun 28, 2008
  50. David JeskeAug 13, 2016
  51. Stephen SinclairJun 28, 2008
  52. David JeskeJun 28, 2008
  53. David JeskeAug 13, 2016
  54. Fwd: An alternate model for preparing partial commitsRobert Anderson, Jun 28, 2008
  55. Dmitry PotapovJun 28, 2008
  56. Robert AndersonJun 28, 2008
  57. Dmitry PotapovJun 28, 2008

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.