git stash 无法应用保存的更改

kum*_*mar 4 git git-stash

我尝试使用以下命令保存 git 状态: git stash save changes_1。我可以使用以下命令查看存储列表: git stash list

但是当我尝试使用以下命令应用存储时:git stash apply stash@{0}。现在,我看不到 git diff 正在更新任何更改。并且显示消息“已经更新!”

因此,简而言之 git stash 无法应用保存的更改。任何帮助。

san*_*mai 5

当之前应用了存储或应用它不执行任何操作(例如当前分支已经有这些更改)时,就会发生这种情况。考虑以下场景:

$ git diff
diff --git a/test.txt b/test.txt
index e69de29..9daeafb 100644
--- a/test.txt
+++ b/test.txt
@@ -0,0 +1 @@
+test

 $ git stash
Saved working directory and index state WIP on master: b1d46d2 test.txt
HEAD is now at b1d46d2 test.txt
Run Code Online (Sandbox Code Playgroud)

现在我们手动重新添加该行并提交:

 $ git diff
diff --git a/test.txt b/test.txt
index e69de29..9daeafb 100644
--- a/test.txt
+++ b/test.txt
@@ -0,0 +1 @@
+test

 $ git commit -a
[master 8efb415] test.txt
 1 files changed, 1 insertions(+), 0 deletions(-)

 $ git stash list
stash@{0}: WIP on master: b1d46d2 test.txt

 $ git stash apply stash@{0}
# On branch master
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)

这里git stash apply什么也不做。