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

Re: [PATCH] update-index: add --swap to swap index and worktree content

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Aug 16, 2011, 14:45 UTC
Message-ID
<CACsJy8DMwqM4rPfAeaXnvDEg1Pv4Y8q7+eJJBeO+ZyaN-m0oZw@mail.gmail.com>
In-Reply-To
<4E4A6A43.7040706@drmicha.warpmail.net>
2011/8/16 Michael J Gruber <git@drmicha.warpmail.net>:
Show 9 quoted lines
> I had to think about that explanation for a while (partly because "git
> add" does not alter the wt either). So, your patch would support the
> following workflow:
>
> git add foo # have index == wt
> hack foo # change foo in wt
> git update-index --swap foo # add foo and reset to previous state
>
> Am I understanding you right? The option could trickle down to "add".

Well, the point is I want to skip the first phase of normal edit path (wt -> index -> commit) and edit index directly (even in parts that are not touched by wt, which means "git add -e" is useless), leaving my wt "unchanged". Sometimes wt is just too dirty I don't want to make any more changes to it while I focus on "index -> commit" phase.

I could add an option to fire up editor with a temporary file containing current index content and automatically update index after editor is closed. But I'd lose the ability to diff my changes. So I do need to wt to change index without losing my current wt. I have to stash my wt somewhere, and index seems a safe place for that.

After swapping, it'd look like index -> wt -> commit, I can do "diff HEAD" to check index vs head. Once I'm done (and create index'), I can swap it back to wt -> index' -> commit.

Thinking a bit more, this may have another use case (for lazy guys like me, anyway). Assume I have separate changes in wt and I'm ready to make many commit. I should make good commits, which means tests (or at least a compile to see I don't miss any changes). So I add related changes to index, then swap wt/index so index becomes wt (and old wt hidden in index). Test what is to be committed. Good? Swap back, commit. Repeat with the rest of changes in wt.

My current workflow is picking changes I believe should go together, commit, then "rebase -i", stopping at each commit to test. It takes longer (especially when I mis-pick changes).

Show 6 quoted lines
> I share the pov that "add -p with e" sometimes doesn't cut it. But
> similarly, the fact that "add -p" can't be used to undo a previous "add
> -p" is suboptimal. Both issues could be solved with a 3way stage tool. I
> have this on my todo/wish list, and I seem to recall that Jeff or Junio
> came up with a few lines of (scripting) code for that. That would depend
> on the availability of proper tools, though (e.g. vim in diff mode).
That'd be great.
-- 
Duy
Previous: Michael J GruberNext: Junio C Hamano
Message 3 of 16 in “update-index: add --swap to swap index and worktree content”
  1. update-index: add --swap to swap index and worktree contentNguyễn Thái Ngọc Duy, Aug 12, 2011
  2. Michael J GruberAug 16, 2011
  3. Nguyen Thai Ngoc DuyAug 16, 2011
  4. Junio C HamanoAug 16, 2011
  5. Jeff KingAug 16, 2011
  6. Junio C HamanoAug 16, 2011
  7. Jeff KingAug 16, 2011
  8. Junio C HamanoAug 16, 2011
  9. Jeff KingAug 16, 2011
  10. Nguyen Thai Ngoc DuyAug 17, 2011
  11. Jeff KingAug 17, 2011
  12. Martin von ZweigbergkAug 17, 2011
  13. Nguyen Thai Ngoc DuyAug 17, 2011
  14. Junio C HamanoAug 17, 2011
  15. Jeff KingAug 17, 2011
  16. Martin von ZweigbergkAug 18, 2011

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.