X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=Documentation%2Fgit-stash.txt;h=473889a660402f5f88b45c6aa3d00d0e85004389;hb=c06951894ac943b2aaa288b0e9dc1eb605dfb7b6;hp=1cc24cc47e3b9845c9d1006ee58faed1bc731c49;hpb=011c181cc656c8b3e48882729d1b6238e8c5c537;p=git.git diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 1cc24cc47..473889a66 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -9,17 +9,18 @@ SYNOPSIS -------- [verse] 'git stash' list [] -'git stash' (show | drop | pop ) [] -'git stash' apply [--index] [] +'git stash' show [] +'git stash' drop [-q|--quiet] [] +'git stash' ( pop | apply ) [--index] [-q|--quiet] [] 'git stash' branch [] -'git stash' [save [--keep-index] []] +'git stash' [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] []] 'git stash' clear 'git stash' create DESCRIPTION ----------- -Use 'git stash' when you want to record the current state of the +Use `git stash` when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the `HEAD` commit. @@ -32,7 +33,7 @@ A stash is by default listed as "WIP on 'branchname' ...", but you can give a more descriptive message on the command line when you create one. -The latest stash you created is stored in `$GIT_DIR/refs/stash`; older +The latest stash you created is stored in `refs/stash`; older stashes are found in the reflog of this reference and can be named using the usual reflog syntax (e.g. `stash@\{0}` is the most recently created stash, `stash@\{1}` is the one before it, `stash@\{2.hours.ago}` @@ -41,15 +42,27 @@ is also possible). OPTIONS ------- -save [--keep-index] []:: +save [--patch] [--[no-]keep-index] [-q|--quiet] []:: 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. + --hard` to revert them. The part is optional and gives + the description along with the stashed state. For quickly making + a snapshot, you can omit _both_ "save" and , but giving + only does not trigger this action to prevent a misspelled + subcommand from making an unwanted stash. + If the `--keep-index` option is used, all changes already added to the index are left intact. ++ +With `--patch`, you can interactively select hunks from in the diff +between HEAD and the working tree to be stashed. The stash entry is +constructed such that its index state is the same as the index state +of your repository, and its worktree contains only the changes you +selected interactively. The selected changes are then rolled back +from your worktree. ++ +The `--patch` option implies `--keep-index`. You can use +`--no-keep-index` to override this. list []:: @@ -64,7 +77,7 @@ stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation stash@{1}: On master: 9cc0589... Add git-stash ---------------------------------------------------------------- + -The command takes options applicable to the 'git-log' +The command takes options applicable to the 'git log' command to control what is shown and how. See linkgit:git-log[1]. show []:: @@ -72,10 +85,10 @@ show []:: Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no `` is given, shows the latest one. By default, the command shows the diffstat, but - it will accept any format known to 'git-diff' (e.g., `git stash show + it will accept any format known to 'git diff' (e.g., `git stash show -p stash@\{1}` to view the second most recent stash in patch form). -pop []:: +pop [--index] [-q|--quiet] []:: Remove a single stashed state from the stash list and apply it on top of the current working tree state, i.e., do the inverse @@ -86,16 +99,16 @@ Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call `git stash drop` manually afterwards. + -When no `` is given, `stash@\{0}` is assumed. See also `apply`. - -apply [--index] []:: - - Like `pop`, but do not remove the state from the stash list. -+ If the `--index` option is used, then tries to reinstate not only the working tree's changes, but also the index's ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). ++ +When no `` is given, `stash@\{0}` is assumed. + +apply [--index] [-q|--quiet] []:: + + Like `pop`, but do not remove the state from the stash list. branch []:: @@ -113,9 +126,10 @@ no conflicts. clear:: Remove all the stashed states. Note that those states will then - be subject to pruning, and may be difficult or impossible to recover. + be subject to pruning, and may be impossible to recover (see + 'Examples' below for a possible strategy). -drop []:: +drop [-q|--quiet] []:: Remove a single stashed state from the stash list. When no `` is given, it removes the latest one. i.e. `stash@\{0}` @@ -187,7 +201,7 @@ $ git reset --soft HEAD^ # ... continue hacking ... ---------------------------------------------------------------- + -You can use 'git-stash' to simplify the above, like this: +You can use 'git stash' to simplify the above, like this: + ---------------------------------------------------------------- # ... hack hack hack ... @@ -216,6 +230,20 @@ $ edit/build/test remaining parts $ git commit foo -m 'Remaining parts' ---------------------------------------------------------------- +Recovering stashes that were cleared/dropped erroneously:: + +If you mistakenly drop or clear stashes, they cannot be recovered +through the normal safety mechanisms. However, you can try the +following incantation to get a list of stashes that are still in your +repository, but not reachable any more: ++ +---------------------------------------------------------------- +git fsck --unreachable | +grep commit | cut -d\ -f3 | +xargs git log --merges --no-walk --grep=WIP +---------------------------------------------------------------- + + SEE ALSO -------- linkgit:git-checkout[1],