Update Friday, 30th of January, Anno Domini MMIX, at the hour of the Buffalo
[git/dscho.git] / source-1233193467.txt
blobb024db637ec61012d9478ff59aec9d43ae12b411
1 Interactive stash
3 There is an easy way to split a patch:
5 <bash>
6 $ git reset HEAD^
7 $ git add -i
8 $ git commit
9 $ git diff -R HEAD@{1} | git apply --index
10 $ git commit
11 </bash>
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:
20 <ol>
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.
26 </ol>
28 Or in code:
30 <bash>
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
43 </bash>
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.