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

Re: Stage, test, and commit only some changes, then repeat

From
Johannes Sixt <j6t@kdbg.org>
Date
Jan 30, 2022, 21:13 UTC
Message-ID
<8db0ee81-c66a-1888-6727-f5ab61cff60f@kdbg.org>
In-Reply-To
<37128901-233F-4428-8A52-470773A18AB0@gmail.com>
Am 30.01.22 um 21:17 schrieb Géry Ogam:
Show 31 quoted lines
> 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?
For example:
1. Stage some changes
2. Commit
3. git stash
4. Test
4a. git commit --amend if tests show that the commit is not yet perfect
5. git stash pop
6. Goto 1.
Be prepared for conflicts in 5 if 4a was necessary.
-- Hannes
Previous: Géry OgamNext: Géry Ogam
Message 2 of 8 in “Stage, test, and commit only some changes, then repeat”
  1. Géry OgamJan 30, 2022
  2. Johannes SixtJan 30, 2022
  3. Géry OgamJan 31, 2022
  4. Sergey OrganovJan 31, 2022
  5. Géry OgamJan 31, 2022
  6. Sergey OrganovJan 31, 2022
  7. Géry OgamJan 31, 2022
  8. Sergey OrganovFeb 1, 2022

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.