1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

指定したPathのファイルのみStashする方法

Last updated at Posted at 2019-10-08

指定したPathのファイルのみStashする方法

検索してもヒットしなかったので、gitのhelpで見つけました。

git stash push -m "message" -- filepath/to/stash

今回のこのやり方はこのコマンドの出力結果から確認できます。

git stash --help
... 

git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
             [-u|--include-untracked] [-a|--all] [-m|--message <message>]
             [--] [<pathspec>...]]
...

       push [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [-m|--message <message>] [--]
       [<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
           pathspecs, which are allowed after a double hyphen -- for disambiguation.

           When pathspec is given to git stash push, the new stash entry records the modified states only for the files that match the
           pathspec. The index entries and working tree files are then rolled back to the state in HEAD only for these files, too, leaving
           files that do not match the pathspec intact.

           If the --keep-index option is used, all changes already added to the index are left intact.

           If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the
           working directory in a very clean state. If the --all option is used instead then the ignored files are stashed and cleaned in
           addition to the untracked files.

           With --patch, you can interactively select hunks from 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. See the "Interactive Mode"
           section of git-add(1) to learn how to operate the --patch mode.

           The --patch option implies --keep-index. You can use --no-keep-index to override this.
...

以前は

git stash save -m "message" -- filepath/to/stash

で出来たような気がしましたが、仕様が変わってしまったのでしょうか。

追記(2019/10/08)

コメントをいただき、 git stash save はdeprecatedになっているそうです。

       save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]
           This option is deprecated in favour of git stash push. It differs from "stash push" in that it cannot take pathspecs, and any
           non-option arguments form the message.
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?