Git:git stashコマンドで退避したエントリーの差分を確認する方法

スポンサーリンク

git stashコマンドで退避したエントリーの差分を確認する方法

git stashコマンドで退避したエントリーの差分を確認するにはshowサブコマンドで-pオプションを指定します。

 

オプションの説明

 show [-u|--include-untracked|--only-untracked] [<diff-options>] [<stash>]
     Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created. By
     default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most
     recent entry in patch form). If no <diff-option> is provided, the default behavior will be given by the stash.showStat, and stash.showPatch config
     variables. You can also use stash.showIncludeUntracked to set whether --include-untracked is enabled by default.

 

-pオプションを指定した場合

$ git diff --cached
diff --git a/test.txt b/test.txt
index de98044..6372083 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,3 @@
 a
-b
 c
+d

$ git stash push
Saved working directory and index state WIP on master: 9f45c01 Initial commit

$ git stash list
stash@{0}: WIP on master: 9f45c01 Initial commit

$ git stash show -p stash@{0}
diff --git a/test.txt b/test.txt
index de98044..6372083 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,3 @@
 a
-b
 c
+d

 

-pオプションを指定しない場合

$ git diff --cached
diff --git a/test.txt b/test.txt
index de98044..6372083 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,3 @@
 a
-b
 c
+d

$ git stash push
Saved working directory and index state WIP on master: 9f45c01 Initial commit

$ git stash list
stash@{0}: WIP on master: 9f45c01 Initial commit

$ git stash show stash@{0}
 test.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)