git stash 无法应用保存的更改

发布于 2024-12-07 19:03:48 字数 221 浏览 0 评论 0原文

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

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

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

I tried saving a git state using : git stash save changes_1.
I can see the stash list using: git stash list

But when I try to apply the stash using: git stash apply stash@{0}.
Now, I cannot see any changes are getting updated with git diff. and it is showing the message "Already uptodate!"

So, in short git stash is not able to apply the changes saved.
Any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中的蝴蝶 2024-12-14 19:03:48

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

$ 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 不执行任何操作。

This happens when a stash was applied previously or applying it does nothing e.g. current branch already has those changes. Consider the following scenario:

$ 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

Now we re-add that line by hand and commit it:

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

Here git stash apply does nothing.

朦胧时间 2024-12-14 19:03:48

尝试 git status -s 看看是否有更改。

如果它们在那里,那么您就已经准备好了,如果没有,请使用 git stash list 并确保您保存的存储位于索引 0 处。如果您尝试应用一个存储,该存储的更改已经是工作分支的一部分,那么它将已经达到日期。

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

Try git status -s to see if the changes are there.

If they are there you are all set, if not use git stash list and make sure your saved stash is at index 0. If you try to apply a stash that has changes that are already part of the working branch it will be already up to date.

If you wanted you could reset your current branch to the last commit. Git reset --hard HEAD and then try to apply that stash again. Care as all current changes not stashed and commits not pushed will be lost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文