Merge branch 'sg/stash-k-i'
* sg/stash-k-i: Documentation: tweak use case in "git stash save --keep-index" stash: introduce 'stash save --keep-index' optionmaint
commit
15fc1c02fc
|
@ -36,12 +36,15 @@ is also possible).
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-------
|
-------
|
||||||
|
|
||||||
save [<message>]::
|
save [--keep-index] [<message>]::
|
||||||
|
|
||||||
Save your local modifications to a new 'stash', and run `git reset
|
Save your local modifications to a new 'stash', and run `git reset
|
||||||
--hard` to revert them. This is the default action when no
|
--hard` to revert them. This is the default action when no
|
||||||
subcommand is given. The <message> part is optional and gives
|
subcommand is given. The <message> part is optional and gives
|
||||||
the description along with the stashed state.
|
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 [<options>]::
|
list [<options>]::
|
||||||
|
|
||||||
|
@ -169,6 +172,24 @@ $ git stash apply
|
||||||
... continue hacking ...
|
... 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 # 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
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
linkgit:git-checkout[1],
|
linkgit:git-checkout[1],
|
||||||
|
|
|
@ -1163,8 +1163,19 @@ _git_show ()
|
||||||
_git_stash ()
|
_git_stash ()
|
||||||
{
|
{
|
||||||
local subcommands='save list show apply clear drop pop create'
|
local subcommands='save list show apply clear drop pop create'
|
||||||
if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
|
local subcommand="$(__git_find_subcommand "$subcommands")"
|
||||||
|
if [ -z "$subcommand" ]; then
|
||||||
__gitcomp "$subcommands"
|
__gitcomp "$subcommands"
|
||||||
|
else
|
||||||
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
case "$subcommand,$cur" in
|
||||||
|
save,--*)
|
||||||
|
__gitcomp "--keep-index"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
git-stash.sh
22
git-stash.sh
|
@ -86,6 +86,13 @@ create_stash () {
|
||||||
}
|
}
|
||||||
|
|
||||||
save_stash () {
|
save_stash () {
|
||||||
|
keep_index=
|
||||||
|
case "$1" in
|
||||||
|
--keep-index)
|
||||||
|
keep_index=t
|
||||||
|
shift
|
||||||
|
esac
|
||||||
|
|
||||||
stash_msg="$1"
|
stash_msg="$1"
|
||||||
|
|
||||||
if no_changes
|
if no_changes
|
||||||
|
@ -104,6 +111,13 @@ save_stash () {
|
||||||
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
|
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
|
||||||
die "Cannot save the current status"
|
die "Cannot save the current status"
|
||||||
printf 'Saved working directory and index state "%s"\n' "$stash_msg"
|
printf 'Saved working directory and index state "%s"\n' "$stash_msg"
|
||||||
|
|
||||||
|
git reset --hard
|
||||||
|
|
||||||
|
if test -n "$keep_index" && test -n $i_tree
|
||||||
|
then
|
||||||
|
git read-tree --reset -u $i_tree
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
have_stash () {
|
have_stash () {
|
||||||
|
@ -153,7 +167,8 @@ apply_stash () {
|
||||||
die "$*: no valid stashed state found"
|
die "$*: no valid stashed state found"
|
||||||
|
|
||||||
unstashed_index_tree=
|
unstashed_index_tree=
|
||||||
if test -n "$unstash_index" && test "$b_tree" != "$i_tree"
|
if test -n "$unstash_index" && test "$b_tree" != "$i_tree" &&
|
||||||
|
test "$c_tree" != "$i_tree"
|
||||||
then
|
then
|
||||||
git diff-tree --binary $s^2^..$s^2 | git apply --cached
|
git diff-tree --binary $s^2^..$s^2 | git apply --cached
|
||||||
test $? -ne 0 &&
|
test $? -ne 0 &&
|
||||||
|
@ -235,7 +250,7 @@ show)
|
||||||
;;
|
;;
|
||||||
save)
|
save)
|
||||||
shift
|
shift
|
||||||
save_stash "$*" && git-reset --hard
|
save_stash "$*"
|
||||||
;;
|
;;
|
||||||
apply)
|
apply)
|
||||||
shift
|
shift
|
||||||
|
@ -268,8 +283,7 @@ pop)
|
||||||
if test $# -eq 0
|
if test $# -eq 0
|
||||||
then
|
then
|
||||||
save_stash &&
|
save_stash &&
|
||||||
echo '(To restore them type "git stash apply")' &&
|
echo '(To restore them type "git stash apply")'
|
||||||
git-reset --hard
|
|
||||||
else
|
else
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue