{"thread":{"id":"57339","subject":"Stage, test, and commit only some changes, then repeat","startedAt":"2022-01-30T20:17:43Z","lastAt":"2022-02-01T08:37:37Z","messageCount":8,"participants":["Géry Ogam","Johannes Sixt","Sergey Organov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"447315","messageId":"37128901-233F-4428-8A52-470773A18AB0@gmail.com","threadId":"57339","inReplyTo":null,"subject":"Stage, test, and commit only some changes, then repeat","fromName":"Géry Ogam","fromEmail":"gery.ogam@gmail.com","sentAt":"2022-01-30T20:17:33Z","receivedAt":"2022-01-30T20:17:43Z","isPatch":false,"sender":{"key":"gery.ogam@gmail.com","avatar":"https://gravatar.com/avatar/30d365bd072fa902ba37a0d8ded409a2484581adf05ba416144c3c40ab7d9f24?d=mp&s=160"},"body":"Hello,\n\nI would like to stage, test, and commit only *some* changes of the working tree, and then repeat this process with the remaining changes.\n\nMy current solution (published at https://stackoverflow.com/a/70914962/2326961):\n\n1. Stage some changes:\n   ```\n   git add -p file\n   ```\n2. Save away the remaining changes:\n   ```\n   git diff >patch\n   git stash push -k\n   ```\n3. Test the staged changes.\n4. Commit the staged changes:\n   ```\n   git commit\n   ```\n5. Restore the remaining changes:\n   ```\n   git apply patch\n   ```\n6. Go to step 1.\n\nIt is not ideal because a) it uses a patch file for saving the remaining changes; b) it uses the stash only for setting the working tree to the index state.\n\nIt would be ideal if I could save *only* the remaining changes in the stash instead of resorting to a patch file. How to do it?\n\nBest,\n\nGéry Ogam\n\n\n[Info système]\nversion git ::\ngit version 2.35.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64 x86_64\ninfo compilateur : clang: 13.0.0 (clang-1300.0.29.3)\ninfo libc : aucune information de libc disponible\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Crochets activés]"},{"id":"447316","messageId":"8db0ee81-c66a-1888-6727-f5ab61cff60f@kdbg.org","threadId":"57339","inReplyTo":"37128901-233F-4428-8A52-470773A18AB0@gmail.com","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-01-30T21:13:45Z","receivedAt":"2022-01-30T21:14:08Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 30.01.22 um 21:17 schrieb Géry Ogam:\n> Hello,\n> \n> I would like to stage, test, and commit only *some* changes of the working tree, and then repeat this process with the remaining changes.\n> \n> My current solution (published at https://stackoverflow.com/a/70914962/2326961):\n> \n> 1. Stage some changes:\n>    ```\n>    git add -p file\n>    ```\n> 2. Save away the remaining changes:\n>    ```\n>    git diff >patch\n>    git stash push -k\n>    ```\n> 3. Test the staged changes.\n> 4. Commit the staged changes:\n>    ```\n>    git commit\n>    ```\n> 5. Restore the remaining changes:\n>    ```\n>    git apply patch\n>    ```\n> 6. Go to step 1.>\n> It is not ideal because a) it uses a patch file for saving the\n> remaining changes; b) it uses the stash only for setting the working\n> tree to the index state.\n> \n> It would be ideal if I could save *only* the remaining changes in the\n> stash instead of resorting to a patch file. How to do it?\nFor example:\n\n1. Stage some changes\n2. Commit\n3. git stash\n4. Test\n4a. git commit --amend if tests show that the commit is not yet perfect\n5. git stash pop\n6. Goto 1.\n\nBe prepared for conflicts in 5 if 4a was necessary.\n\n-- Hannes\n"},{"id":"447342","messageId":"87bkzrvpjv.fsf@osv.gnss.ru","threadId":"57339","inReplyTo":"37128901-233F-4428-8A52-470773A18AB0@gmail.com","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2022-01-31T16:27:16Z","receivedAt":"2022-01-31T16:29:43Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Géry Ogam <gery.ogam@gmail.com> writes:\n\n> Hello,\n>\n> I would like to stage, test, and commit only *some* changes of the\n> working tree, and then repeat this process with the remaining changes.\n>\n> My current solution (published at\n> https://stackoverflow.com/a/70914962/2326961):\n>\n> 1. Stage some changes:\n>    ```\n>    git add -p file\n>    ```\n> 2. Save away the remaining changes:\n>    ```\n>    git diff >patch\n>    git stash push -k\n>    ```\n> 3. Test the staged changes.\n> 4. Commit the staged changes:\n>    ```\n>    git commit\n>    ```\n> 5. Restore the remaining changes:\n>    ```\n>    git apply patch\n>    ```\n> 6. Go to step 1.\n>\n> It is not ideal because a) it uses a patch file for saving the\n> remaining changes; b) it uses the stash only for setting the working\n> tree to the index state.\n>\n> It would be ideal if I could save *only* the remaining changes in the\n> stash instead of resorting to a patch file. How to do it?\n\nIt looks like you don't need patch file for this workflow. What's wrong with:\n\ngit add...\ngit stash push --keep-index\n... check, git add fixes\ngit commit\ngit stash apply\n\n???\n\n-- Sergey Organov\n"},{"id":"447363","messageId":"49031AA3-CDC3-4CF6-A04B-E3533907FCA4@gmail.com","threadId":"57339","inReplyTo":"87bkzrvpjv.fsf@osv.gnss.ru","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Géry Ogam","fromEmail":"gery.ogam@gmail.com","sentAt":"2022-01-31T21:33:39Z","receivedAt":"2022-01-31T21:33:43Z","isPatch":false,"sender":{"key":"gery.ogam@gmail.com","avatar":"https://gravatar.com/avatar/30d365bd072fa902ba37a0d8ded409a2484581adf05ba416144c3c40ab7d9f24?d=mp&s=160"},"body":"> Le 31 janv. 2022 à 17:27, Sergey Organov <sorganov@gmail.com> a écrit :\n> \n> Géry Ogam <gery.ogam@gmail.com> writes:\n> \n>> Hello,\n>> \n>> I would like to stage, test, and commit only *some* changes of the\n>> working tree, and then repeat this process with the remaining changes.\n>> \n>> My current solution (published at\n>> https://stackoverflow.com/a/70914962/2326961):\n>> \n>> 1. Stage some changes:\n>>   ```\n>>   git add -p file\n>>   ```\n>> 2. Save away the remaining changes:\n>>   ```\n>>   git diff >patch\n>>   git stash push -k\n>>   ```\n>> 3. Test the staged changes.\n>> 4. Commit the staged changes:\n>>   ```\n>>   git commit\n>>   ```\n>> 5. Restore the remaining changes:\n>>   ```\n>>   git apply patch\n>>   ```\n>> 6. Go to step 1.\n>> \n>> It is not ideal because a) it uses a patch file for saving the\n>> remaining changes; b) it uses the stash only for setting the working\n>> tree to the index state.\n>> \n>> It would be ideal if I could save *only* the remaining changes in the\n>> stash instead of resorting to a patch file. How to do it?\n> \n> It looks like you don't need patch file for this workflow. What's wrong with:\n> \n> git add...\n> git stash push --keep-index\n> ... check, git add fixes\n> git commit\n> git stash apply\n> \n> ???\n> \n> -- Sergey Organov\n\nHello Sergey,\n\n`git stash` saves the transition from the HEAD state to the working tree state. It also sets the working tree to the *HEAD* state.\n\n`git stash --keep-index` saves the transition from the HEAD state to the working tree state. It also sets the working tree to the *index* state.\n\n`git stash pop` applies the last saved transition. So if the working tree was not in HEAD state (like after `git stash --keep-index`), there will be a conflict.\n\nBest,\n\nGéry Ogam"},{"id":"447366","messageId":"87iltzpo1r.fsf@osv.gnss.ru","threadId":"57339","inReplyTo":"49031AA3-CDC3-4CF6-A04B-E3533907FCA4@gmail.com","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2022-01-31T21:56:16Z","receivedAt":"2022-01-31T21:56:38Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Géry Ogam <gery.ogam@gmail.com> writes:\n\n>> Le 31 janv. 2022 à 17:27, Sergey Organov <sorganov@gmail.com> a écrit :\n>> \n>> Géry Ogam <gery.ogam@gmail.com> writes:\n>> \n>>> Hello,\n>>> \n>>> I would like to stage, test, and commit only *some* changes of the\n>>> working tree, and then repeat this process with the remaining changes.\n>>> \n>>> My current solution (published at\n>>> https://stackoverflow.com/a/70914962/2326961):\n>>> \n>>> 1. Stage some changes:\n>>>   ```\n>>>   git add -p file\n>>>   ```\n>>> 2. Save away the remaining changes:\n>>>   ```\n>>>   git diff >patch\n>>>   git stash push -k\n>>>   ```\n>>> 3. Test the staged changes.\n>>> 4. Commit the staged changes:\n>>>   ```\n>>>   git commit\n>>>   ```\n>>> 5. Restore the remaining changes:\n>>>   ```\n>>>   git apply patch\n>>>   ```\n>>> 6. Go to step 1.\n>>> \n>>> It is not ideal because a) it uses a patch file for saving the\n>>> remaining changes; b) it uses the stash only for setting the working\n>>> tree to the index state.\n>>> \n>>> It would be ideal if I could save *only* the remaining changes in the\n>>> stash instead of resorting to a patch file. How to do it?\n>> \n>> It looks like you don't need patch file for this workflow. What's wrong with:\n>> \n>> git add...\n>> git stash push --keep-index\n>> ... check, git add fixes\n>> git commit\n>> git stash apply\n>> \n>> ???\n>> \n>> -- Sergey Organov\n>\n> Hello Sergey,\n>\n> `git stash` saves the transition from the HEAD state to the working\n> tree state. It also sets the working tree to the *HEAD* state.\n>\n> `git stash --keep-index` saves the transition from the HEAD state to\n> the working tree state. It also sets the working tree to the *index*\n> state.\n>\n> `git stash pop` applies the last saved transition. So if the working\n> tree was not in HEAD state (like after `git stash --keep-index`),\n> there will be a conflict.\n\nDid you actually try it and got conflict? I doubt there will be any if\nyou don't modify anything after \"git stash --keep-index\" during testing,\nand if you do, than any method might bring conflicts.\n\nIn fact I just re-tested this to make sure, and got no conflicts.\n\n-- Sergey Organov\n"},{"id":"447367","messageId":"74E376B9-40D3-4F88-AC23-0FADECA69BB4@gmail.com","threadId":"57339","inReplyTo":"8db0ee81-c66a-1888-6727-f5ab61cff60f@kdbg.org","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Géry Ogam","fromEmail":"gery.ogam@gmail.com","sentAt":"2022-01-31T21:57:17Z","receivedAt":"2022-01-31T21:58:13Z","isPatch":false,"sender":{"key":"gery.ogam@gmail.com","avatar":"https://gravatar.com/avatar/30d365bd072fa902ba37a0d8ded409a2484581adf05ba416144c3c40ab7d9f24?d=mp&s=160"},"body":"> Le 30 janv. 2022 à 22:13, Johannes Sixt <j6t@kdbg.org> a écrit :\n> \n> Am 30.01.22 um 21:17 schrieb Géry Ogam:\n>> Hello,\n>> \n>> I would like to stage, test, and commit only *some* changes of the working tree, and then repeat this process with the remaining changes.\n>> \n>> My current solution (published at https://stackoverflow.com/a/70914962/2326961):\n>> \n>> 1. Stage some changes:\n>>   ```\n>>   git add -p file\n>>   ```\n>> 2. Save away the remaining changes:\n>>   ```\n>>   git diff >patch\n>>   git stash push -k\n>>   ```\n>> 3. Test the staged changes.\n>> 4. Commit the staged changes:\n>>   ```\n>>   git commit\n>>   ```\n>> 5. Restore the remaining changes:\n>>   ```\n>>   git apply patch\n>>   ```\n>> 6. Go to step 1.>\n>> It is not ideal because a) it uses a patch file for saving the\n>> remaining changes; b) it uses the stash only for setting the working\n>> tree to the index state.\n>> \n>> It would be ideal if I could save *only* the remaining changes in the\n>> stash instead of resorting to a patch file. How to do it?\n> For example:\n> \n> 1. Stage some changes\n> 2. Commit\n> 3. git stash\n> 4. Test\n> 4a. git commit --amend if tests show that the commit is not yet perfect\n> 5. git stash pop\n> 6. Goto 1.\n> \n> Be prepared for conflicts in 5 if 4a was necessary.\n> \n> -- Hannes\n\n\nHello Johannes,\n\nThanks for the solution! I think you can avoid conflicts in step 5 by popping off the stash right before step 4a and pushing on the stash right after, like this (the three columns represent the state of the working tree, index, and HEAD):\n\n\nedit\nX X X\nY\nZ\n\ngit add Y\nX X X\nY Y\nZ\n\ngit commit\nX X X\nY Y Y\nZ\n\ngit stash push (saves X Y +Z)\nX X X\nY Y Y\n\nwhile test fails {\n\ngit stash pop (restores X Y +Z)\nX X X\nY Y Y\nZ\n\nedit\nX X X\nY'Y Y\nZ\n\ngit add Y'\nX X X\nY'Y'Y\nZ\n\ngit commit --amend\nX X X\nY'Y'Y'\nZ\n\ngit stash push (saves X Y' +Z)\nX X X\nY'Y'Y'\n\n}\n\ngit stash pop (restores X Y +Z)\nX X X\nY Y Y\nZ\n\n\nBut the problem with your solution is that you commit before testing and then amend in case of test failure.\n\nThe option --keep-index of the command git stash push is supposed to handle this, like specified in the reference documentation:\nhttps://git-scm.com/docs/git-stash#Documentation/git-stash.txt-Testingpartialcommits\n\n\nTesting partial commits\n\nYou can use git stash push --keep-index when you want to make two or more commits out of the changes in the work tree, and you want to test each change before committing:\n\n# ... hack hack hack ...\n$ git add --patch foo            # add just first part to the index\n$ git stash push --keep-index    # save all other changes to the stash\n$ edit/build/test first part\n$ git commit -m 'First part'     # commit fully tested change\n$ git stash pop                  # prepare to work on all other changes\n# ... repeat above five steps until one commit remains ...\n$ edit/build/test remaining parts\n$ git commit foo -m 'Remaining parts'\n\n\nBut --keep-index is fundamentally flawed because though it sets the working tree to the index state (instead of the HEAD state like bare git stash push), it still saves the changes between the HEAD state and the working tree state (i.e. staged changes and unstaged changes). So when you git stash pop, you get conflicts since the working tree is not in the HEAD state like expected, but in the index state.\n\nPeople have been complaining about this conflict issue on Stack Overflow many times:\nhttps://stackoverflow.com/q/7650797/2326961\nhttps://stackoverflow.com/q/20028507/2326961\nhttps://stackoverflow.com/q/49301304/2326961\nhttps://stackoverflow.com/q/25620844/2326961\nhttps://stackoverflow.com/q/20681448/2326961\nhttps://stackoverflow.com/q/57524906/2326961\n\nFEATURE REQUEST\nSo could we add a new option -U|--unstaged (by symmetry with the existing option -S|--staged) to the command git stash push to do what the option --keep-index was trying to achieve? It would:\n— save the changes between the index state and the working tree state, i.e. only unstaged changes;\n— set the working tree in the index state.\n\nSo the difference with --keep-index is the source: the changes would be computed from the index instead of from HEAD.\n\nWith that new option -U|--unstaged, we could solve the ‘testing partial changes before committing’ problem elegantly (called ‘Testing partial commits’ in the reference documentation, which is a bit misleading), that is\n— without conflicts contrary to the solution in the reference documentation:\n git stash push --keep-index\n test\n git commit\n git stash pop\n— without temporary commits contrary to your suggested solution:\n git commit\n git stash push\n test\n git commit --amend\n git stash pop\n— without temporary files contrary to my solution:\n git diff >unstaged\n git restore .\n test\n git commit\n git apply unstaged\n rm unstaged\n\nLike this:\n\n\nedit\nX X X\nY\nZ\n\ngit add Y\nX X X\nY Y\nZ\n\ngit stash push --unstaged (saves X Y +Z, not X +Y +Z like --keep-index does)\nX X X\nY Y\n\nwhile test fails {\n\ngit stash pop (restores X Y +Z)\nX X X\nY Y\nZ\n\nedit\nX X X\nY'Y\nZ\n\ngit add Y'\nX X X\nY'Y'\nZ\n\ngit stash push --unstaged (saves X Y' +Z)\nX X X\nY'Y'\n\n}\n\ngit commit\nX X X\nY Y Y\n\ngit stash pop (restores X Y +Z)\nX X X\nY Y Y\nZ\n\n\nBest,\n\nGéry Ogam"},{"id":"447376","messageId":"0558E792-899A-4B08-B0A1-4844E5D1EFF2@gmail.com","threadId":"57339","inReplyTo":"87iltzpo1r.fsf@osv.gnss.ru","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Géry Ogam","fromEmail":"gery.ogam@gmail.com","sentAt":"2022-01-31T22:22:10Z","receivedAt":"2022-01-31T22:22:14Z","isPatch":false,"sender":{"key":"gery.ogam@gmail.com","avatar":"https://gravatar.com/avatar/30d365bd072fa902ba37a0d8ded409a2484581adf05ba416144c3c40ab7d9f24?d=mp&s=160"},"body":"> Le 31 janv. 2022 à 22:56, Sergey Organov <sorganov@gmail.com> a écrit :\n> \n> Géry Ogam <gery.ogam@gmail.com> writes:\n> \n>>> Le 31 janv. 2022 à 17:27, Sergey Organov <sorganov@gmail.com> a écrit :\n>>> \n>>> Géry Ogam <gery.ogam@gmail.com> writes:\n>>> \n>>>> Hello,\n>>>> \n>>>> I would like to stage, test, and commit only *some* changes of the\n>>>> working tree, and then repeat this process with the remaining changes.\n>>>> \n>>>> My current solution (published at\n>>>> https://stackoverflow.com/a/70914962/2326961):\n>>>> \n>>>> 1. Stage some changes:\n>>>>  ```\n>>>>  git add -p file\n>>>>  ```\n>>>> 2. Save away the remaining changes:\n>>>>  ```\n>>>>  git diff >patch\n>>>>  git stash push -k\n>>>>  ```\n>>>> 3. Test the staged changes.\n>>>> 4. Commit the staged changes:\n>>>>  ```\n>>>>  git commit\n>>>>  ```\n>>>> 5. Restore the remaining changes:\n>>>>  ```\n>>>>  git apply patch\n>>>>  ```\n>>>> 6. Go to step 1.\n>>>> \n>>>> It is not ideal because a) it uses a patch file for saving the\n>>>> remaining changes; b) it uses the stash only for setting the working\n>>>> tree to the index state.\n>>>> \n>>>> It would be ideal if I could save *only* the remaining changes in the\n>>>> stash instead of resorting to a patch file. How to do it?\n>>> \n>>> It looks like you don't need patch file for this workflow. What's wrong with:\n>>> \n>>> git add...\n>>> git stash push --keep-index\n>>> ... check, git add fixes\n>>> git commit\n>>> git stash apply\n>>> \n>>> ???\n>>> \n>>> -- Sergey Organov\n>> \n>> Hello Sergey,\n>> \n>> `git stash` saves the transition from the HEAD state to the working\n>> tree state. It also sets the working tree to the *HEAD* state.\n>> \n>> `git stash --keep-index` saves the transition from the HEAD state to\n>> the working tree state. It also sets the working tree to the *index*\n>> state.\n>> \n>> `git stash pop` applies the last saved transition. So if the working\n>> tree was not in HEAD state (like after `git stash --keep-index`),\n>> there will be a conflict.\n> \n> Did you actually try it and got conflict? I doubt there will be any if\n> you don't modify anything after \"git stash --keep-index\" during testing,\n> and if you do, than any method might bring conflicts.\n> \n> In fact I just re-tested this to make sure, and got no conflicts.\n> \n> -- Sergey Organov\n\ngit init\ntouch file\ngit add file\ngit commit\necho one >>file\ngit add file\necho two >>file\ngit stash push --keep-index\ngit stash pop\n\nGéry Ogam"},{"id":"447398","messageId":"87fsp3nfsp.fsf@osv.gnss.ru","threadId":"57339","inReplyTo":"0558E792-899A-4B08-B0A1-4844E5D1EFF2@gmail.com","subject":"Re: Stage, test, and commit only some changes, then repeat","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2022-02-01T08:37:26Z","receivedAt":"2022-02-01T08:37:37Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Géry Ogam <gery.ogam@gmail.com> writes:\n\n>> Le 31 janv. 2022 à 22:56, Sergey Organov <sorganov@gmail.com> a écrit :\n>> \n>> Géry Ogam <gery.ogam@gmail.com> writes:\n>> \n>>>> Le 31 janv. 2022 à 17:27, Sergey Organov <sorganov@gmail.com> a écrit :\n>>>> \n>>>> Géry Ogam <gery.ogam@gmail.com> writes:\n>>>> \n>>>>> Hello,\n>>>>> \n>>>>> I would like to stage, test, and commit only *some* changes of the\n>>>>> working tree, and then repeat this process with the remaining changes.\n>>>>> \n>>>>> My current solution (published at\n>>>>> https://stackoverflow.com/a/70914962/2326961):\n>>>>> \n>>>>> 1. Stage some changes:\n>>>>>  ```\n>>>>>  git add -p file\n>>>>>  ```\n>>>>> 2. Save away the remaining changes:\n>>>>>  ```\n>>>>>  git diff >patch\n>>>>>  git stash push -k\n>>>>>  ```\n>>>>> 3. Test the staged changes.\n>>>>> 4. Commit the staged changes:\n>>>>>  ```\n>>>>>  git commit\n>>>>>  ```\n>>>>> 5. Restore the remaining changes:\n>>>>>  ```\n>>>>>  git apply patch\n>>>>>  ```\n>>>>> 6. Go to step 1.\n>>>>> \n>>>>> It is not ideal because a) it uses a patch file for saving the\n>>>>> remaining changes; b) it uses the stash only for setting the working\n>>>>> tree to the index state.\n>>>>> \n>>>>> It would be ideal if I could save *only* the remaining changes in the\n>>>>> stash instead of resorting to a patch file. How to do it?\n>>>> \n>>>> It looks like you don't need patch file for this workflow. What's\n>>>> wrong with:\n>>>> \n>>>> git add...\n>>>> git stash push --keep-index\n>>>> ... check, git add fixes\n>>>> git commit\n>>>> git stash apply\n>>>> \n>>>> ???\n>>>> \n>>>> -- Sergey Organov\n>>> \n>>> Hello Sergey,\n>>> \n>>> `git stash` saves the transition from the HEAD state to the working\n>>> tree state. It also sets the working tree to the *HEAD* state.\n>>> \n>>> `git stash --keep-index` saves the transition from the HEAD state to\n>>> the working tree state. It also sets the working tree to the *index*\n>>> state.\n>>> \n>>> `git stash pop` applies the last saved transition. So if the working\n>>> tree was not in HEAD state (like after `git stash --keep-index`),\n>>> there will be a conflict.\n>> \n>> Did you actually try it and got conflict? I doubt there will be any if\n>> you don't modify anything after \"git stash --keep-index\" during testing,\n>> and if you do, than any method might bring conflicts.\n>> \n>> In fact I just re-tested this to make sure, and got no conflicts.\n>> \n>> -- Sergey Organov\n>\n> git init\n> touch file\n> git add file\n> git commit\n> echo one >>file\n> git add file\n> echo two >>file\n> git stash push --keep-index\n> git stash pop\n\nYep, if you have overlapping changes in work-tree and in the index, it\nwill happen indeed. I've rather tested handling of non-overlapping\nchanges in the same file that occurs much more often in practice, at\nleast for me.\n\nBTW, for reference, Emacs's magit, that is essentially alternate Git\nporcelain, has support for all 4 possible modes of stashing:\n\nz Save                  Z Snapshot          \ni Save index            I Snapshot index    \nw Save worktree         W Snapshot worktree \nx Save keeping index    r Snapshot to wipref\n\nFor Git itself I've recently added --staged/-S, so the only mode that is\nstill missing is --worktree indeed.\n\n-- Sergey Organov\n"}]}