From: Junio C Hamano Date: Sun, 13 Jul 2008 22:15:27 +0000 (-0700) Subject: Merge branch 'sg/stash-k-i' X-Git-Tag: v1.6.0-rc0~87 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/15fc1c02fce2ee6a8a3f625bf24dd782fd905904?hp=-c 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' option --- 15fc1c02fce2ee6a8a3f625bf24dd782fd905904 diff --combined Documentation/git-stash.txt index 9b6b911091,e2c8722376..e42c5eff4d --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@@ -36,12 -36,15 +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 []:: @@@ -56,7 -59,7 +59,7 @@@ stash@{0}: WIP on submit: 6ebd0e2... Up 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 []:: @@@ -64,7 -67,7 +67,7 @@@ 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). apply [--index] []:: @@@ -158,7 -161,7 +161,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 ... @@@ -169,6 -172,24 +172,24 @@@ $ git stash appl ... 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 -------- linkgit:git-checkout[1], diff --combined contrib/completion/git-completion.bash index 27332ed8b1,595de80ea4..84a256ec54 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@@ -451,18 -451,6 +451,18 @@@ __git_find_subcommand ( done } +__git_has_doubledash () +{ + local c=1 + while [ $c -lt $COMP_CWORD ]; do + if [ "--" = "${COMP_WORDS[c]}" ]; then + return 0 + fi + c=$((++c)) + done + return 1 +} + __git_whitespacelist="nowarn warn error error-all strip" _git_am () @@@ -509,8 -497,6 +509,8 @@@ _git_apply ( _git_add () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) @@@ -525,9 -511,7 +525,9 @@@ _git_bisect () { - local subcommands="start bad good reset visualize replay log" + __git_has_doubledash && return + + local subcommands="start bad good skip reset visualize replay log run" local subcommand="$(__git_find_subcommand "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" @@@ -535,7 -519,7 +535,7 @@@ fi case "$subcommand" in - bad|good|reset) + bad|good|reset|skip) __gitcomp "$(__git_refs)" ;; *) @@@ -562,7 -546,7 +562,7 @@@ _git_branch ( --*) __gitcomp " --color --no-color --verbose --abbrev= --no-abbrev - --track --no-track + --track --no-track --contains --merged --no-merged " ;; *) @@@ -629,8 -613,6 +629,8 @@@ _git_cherry_pick ( _git_commit () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) @@@ -650,8 -632,6 +650,8 @@@ _git_describe ( _git_diff () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) @@@ -754,8 -734,6 +754,8 @@@ _git_ls_tree ( _git_log () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --pretty=*) @@@ -1108,8 -1086,6 +1108,8 @@@ _git_remote ( _git_reset () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) @@@ -1122,8 -1098,6 +1122,8 @@@ _git_shortlog () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in --*) @@@ -1163,15 -1137,24 +1163,26 @@@ _git_show ( _git_stash () { 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" + else + local cur="${COMP_WORDS[COMP_CWORD]}" + case "$subcommand,$cur" in + save,--*) + __gitcomp "--keep-index" + ;; + *) + COMPREPLY=() + ;; + esac fi } _git_submodule () { + __git_has_doubledash && return + local subcommands="add status init update" if [ -z "$(__git_find_subcommand "$subcommands")" ]; then local cur="${COMP_WORDS[COMP_CWORD]}" @@@ -1378,8 -1361,6 +1389,8 @@@ _git ( _gitk () { + __git_has_doubledash && return + local cur="${COMP_WORDS[COMP_CWORD]}" local g="$(git rev-parse --git-dir 2>/dev/null)" local merge=""