From 7bedebcaad351108a8f6eab6a031f2be2c06b613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Fri, 27 Jun 2008 16:37:15 +0200 Subject: stash: introduce 'stash save --keep-index' option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'git stash save' saves local modifications to a new stash, and runs 'git reset --hard' to revert them to a clean index and work tree. When the '--keep-index' option is specified, after that 'git reset --hard' the previous contents of the index is restored and the work tree is updated to match the index. This option is useful if the user wants to commit only parts of his local modifications, but wants to test those parts before committing. Also add support for the completion of the new option, and add an example use case to the documentation. Signed-off-by: SZEDER Gábor Signed-off-by: Junio C Hamano --- Documentation/git-stash.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'Documentation/git-stash.txt') diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 23ac33129..8f331ee7d 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -36,12 +36,15 @@ is also possible). OPTIONS ------- -save []:: +save [--keep-index] []:: Save your local modifications to a new 'stash', and run `git reset --hard` to revert them. This is the default action when no subcommand is given. The part is optional and gives the description along with the stashed state. ++ +If the `--keep-index` option is used, all changes already added to the +index are left intact. list []:: @@ -169,6 +172,23 @@ $ git stash apply ... continue hacking ... ---------------------------------------------------------------- +Testing partial commits:: + +You can use `git stash save --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: ++ +---------------------------------------------------------------- +... hack hack hack ... +$ git add --patch foo +$ git stash save --keep-index +$ build && run tests +$ git commit -m 'First part' +$ git stash apply +$ build && run tests +$ git commit -a -m 'Second part' +---------------------------------------------------------------- + SEE ALSO -------- linkgit:git-checkout[1], -- cgit v1.2.1 From caf1899699b2255111a3db335553e31f3718c1c9 Mon Sep 17 00:00:00 2001 From: Eric Raible Date: Tue, 8 Jul 2008 00:40:56 -0700 Subject: Documentation: tweak use case in "git stash save --keep-index" The documentation suggests using "git stash apply" in the --keep-index workflow even though doing so will lead to clutter in the stash. And given that the changes are about to be committed anyway "git stash pop" is more sensible. Additionally the text preceeding the example claims that it works for "two or more commits", but the example itself is really tailored for just two. Expanding it just a little makes it clear how the procedure generalizes to N commits. Finally the example is annotated with some commentary to explain things on a line-by-line basis. --- Documentation/git-stash.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Documentation/git-stash.txt') diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 8f331ee7d..e2c872237 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -180,13 +180,14 @@ each change before committing: + ---------------------------------------------------------------- ... hack hack hack ... -$ git add --patch foo -$ git stash save --keep-index -$ build && run tests -$ git commit -m 'First part' -$ git stash apply -$ build && run tests -$ git commit -a -m 'Second part' +$ git add --patch foo # add just first part to the index +$ git stash save --keep-index # save all other changes to the stash +$ edit/build/test first part +$ git commit foo -m 'First part' # commit fully tested change +$ git stash pop # prepare to work on all other changes +... repeat above five steps until one commit remains ... +$ edit/build/test remaining parts +$ git commit foo -m 'Remaining parts' ---------------------------------------------------------------- SEE ALSO -- cgit v1.2.1