Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git stash save --keep-index の記述と実際の動作に相違あり? #26

Open
harupong opened this issue Nov 21, 2014 · 1 comment

Comments

@harupong
Copy link
Member

There are a few stash variants that may also be helpful. The first option that is quite popular is the --keep-index option to the stash save command. This tells Git to not stash anything that you've already staged with the git add command.

v2で追加されたこの段落、「git stash save --keep-indexでstashすると、git addでインデックスに追加した内容はstashされないようにできる」という解釈で間違いないはず。けれど、このコマンドを実行すると、インデックスに追加されていた内容はstashされて、かつインデックスに残ったままになる。

ちなみに、ドキュメント には

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

とある。

なお、git version 2.1.3(On ubuntu) と git version 1.9.4.msysgit.1 で試して同じ挙動だった。以下はgit version 2.1.3のログ。

@harupong harupong added the ch07 label Nov 21, 2014
@harupong
Copy link
Member Author

$ git --version
git version 2.1.3
$ git stash list
$ vi README.md
$ git add README.md
$ git status
On branch markdown
Your branch is up-to-date with 'origin/markdown'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.md

$ git diff --staged
diff --git a/README.md b/README.md
index cd87828..f8f9682 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-README
+# README

 ## レビューするファイル

⬆️ Stash is empty. I editted one file and added that to index.

$ git stash save --keep-index
Saved working directory and index state WIP on markdown: 3f347db Apply upstream changes to markdown files
HEAD is now at 3f347db Apply upstream changes to markdown files

⬆️ Then I stashed the change using --keep-index option.

$ git stash list
stash@{0}: WIP on markdown: 3f347db Apply upstream changes to markdown files
$ git stash show stash@{0}
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git stash show -p stash@{0}
diff --git a/README.md b/README.md
index cd87828..f8f9682 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-README
+# README

 ## レビューするファイル

⬆️ One stash is created, with the changes I staged earlier.

$ git status
On branch markdown
Your branch is up-to-date with 'origin/markdown'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.md

$ git diff --staged
diff --git a/README.md b/README.md
index cd87828..f8f9682 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-README
+# README

 ## レビューするファイル

⬆️ index is unchanged, which is the expected behavior of --keep-index option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant