Git:git stashコマンドでファイルを指定して退避する方法

スポンサーリンク

git stashコマンドでファイルを指定して退避する方法

git stashコマンドでファイルを指定して退避するにはpushサブコマンドで--のあとにファイルを指定します。

 

オプションの説明

 push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--pathspec-from-file=<file>
 [--pathspec-file-nul]] [--] [<pathspec>...]
     Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index). The <message> part is optional and
     gives the description along with the stashed state.

     For quickly making a snapshot, you can omit "push". In this mode, non-option arguments are not allowed to prevent a misspelled subcommand from making an
     unwanted stash entry. The two exceptions to this are stash -p which acts as alias for stash push -p and pathspec elements, which are allowed after a
     double hyphen -- for disambiguation.

 

--のあとにファイルを指定した場合

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   a.txt
        new file:   b.txt
        new file:   c.txt

$ git stash push -- a.txt c.txt
Saved working directory and index state WIP on master: 8b7c11b866 The fifth batch

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   b.txt

 

ファイルを指定しない場合

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   a.txt
        new file:   b.txt
        new file:   c.txt

$ git stash push
Saved working directory and index state WIP on master: 8b7c11b866 The fifth batch

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean