3 There is an easy way to split a patch:
9 $ git diff -R HEAD@{1} | git apply --index
13 but it misses out on the fact that the first of both commits does not
14 reflect the state of the working directory at any time.
16 So I think something like an interactive ''stash'' is needed. A method
17 to specify what you want to keep in the working directory, the rest should
18 be stashed. The idea would be something like this:
21 <li>Add the desired changes into a temporary index.
22 <li>Put the rest of the changes in another temporary index.
23 <li>Stash the latter index.
24 <li>Synchronize the working directory with the first index.
25 <li>Clean up temporary indices.
31 $ cp .git/index .git/interactive-stash-1
32 $ GIT_INDEX_FILE=.git/interactive-stash-1 git add -i
33 $ cp .git/index .git/interactive-stash-2
34 $ GIT_INDEX_FILE=.git/interactive-stash-1 git diff -R |
35 (GIT_INDEX_FILE=.git/interactive-stash-2 git apply--index)
36 $ tree=$(GIT_INDEX_FILE=.git/index git write-tree)
37 $ commit=$(echo Current index | git commit-tree $tree -p HEAD)
38 $ tree=$(GIT_INDEX_FILE=.git/interactive-stash-2 git write-tree)
39 $ commit=$(echo Edited out | git commit-tree $tree -p HEAD -p $commit)
40 $ git update-ref refs/stash $commit
41 $ GIT_INDEX_FILE=.git/interactive-stash-1 git checkout-index -a -f
42 $ rm .git/interactive-stash-1 .git/interactive-stash-2
45 This should probably go into ''git-stash.sh'', maybe even with a switch
46 to start git-gui to do the interactive adding instead of git-add.