From: Sergey Organov Date: Mon, 31 Jan 2022 16:27:16 GMT Subject: Re: Stage, test, and commit only some changes, then repeat Message-ID: <87bkzrvpjv.fsf@osv.gnss.ru> In-Reply-To: <37128901-233F-4428-8A52-470773A18AB0@gmail.com> Géry Ogam writes: > Hello, > > I would like to stage, test, and commit only *some* changes of the > working tree, and then repeat this process with the remaining changes. > > My current solution (published at > https://stackoverflow.com/a/70914962/2326961): > > 1. Stage some changes: > ``` > git add -p file > ``` > 2. Save away the remaining changes: > ``` > git diff >patch > git stash push -k > ``` > 3. Test the staged changes. > 4. Commit the staged changes: > ``` > git commit > ``` > 5. Restore the remaining changes: > ``` > git apply patch > ``` > 6. Go to step 1. > > It 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. > > It 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? It looks like you don't need patch file for this workflow. What's wrong with: git add... git stash push --keep-index ... check, git add fixes git commit git stash apply ??? -- Sergey Organov