3

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

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

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

4

2 回答 2

4

这种情况发生在之前应用了存储或应用它什么都不做时,例如当前分支已经有这些更改。考虑以下场景:

$ 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

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

 $ 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)

这里git stash apply什么都不做。

于 2011-10-04T06:38:42.373 回答
2

试试 git status -s 看看有没有变化。

如果它们在那里,则一切就绪,如果不使用 git stash list 并确保您保存的存储在索引 0 处。如果您尝试应用具有已属于工作分支的更改的存储,它将已经达到日期。

如果您愿意,可以将当前分支重置为最后一次提交。Git reset --hard HEAD 然后尝试再次应用该存储。小心,因为所有当前未隐藏的更改和未推送的提交都将丢失。

于 2011-10-04T06:04:38.403 回答