奇怪的混帐案 - 混帐隐藏后面的Git隐藏申请丢失未提交的数据? [英] Strange git case - git stash followed by git stash apply lost uncommitted data?

查看:130
本文介绍了奇怪的混帐案 - 混帐隐藏后面的Git隐藏申请丢失未提交的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,让我们说file.txt我已经完成了git mv file.txt到file1.txt,然后我创建了一个名为file.txt的新文件并对其进行了处理。不幸的是,我没有将该文件添加到git中。无论如何,问题是我做了git存储,然后git存储适用,但新的file.txt消失了...无论如何得到它?

I have a file, let's say file.txt I have done git mv file.txt to file1.txt, then I created a new file called file.txt and worked on it. Unfortunately I didn't add that file to git yet. Anyway the problem is that I did git stash, then git stash apply, but the new file.txt disappeared... anyway to get it back?

推荐答案

这里的问题主要是对 git存储保存的误解。它仅保存对被跟踪文件的更改。未追踪的文件不会被 git存储保存。当您将file.txt移至file1.txt时,新的file.txt是未跟踪的文件,不会 git stash 保存。这不是一个错误,它只是 git stash 行为的方式。这可能是 git stash 的文档应该更清楚。

The problem here is mostly a misunderstanding of what git stash save does. It saves only changes to tracked files. Untracked files are not saved by git stash. When you moved file.txt to file1.txt, the new file.txt is an untracked file and will not be saved by git stash. This isn't a bug, it's just the way that git stash behaves. It could be that the documentation for git stash should be more clear about this.

作为<$的文档c $ c> git stash save states,它会在保存更改后执行 git reset --hard 。这是覆盖新文件.txt的 git reset --hard 。有人可能会争辩说,如果未覆盖的文件被覆盖,那么 git reset --hard 应该会生成警告,但我仍然不会将其称为错误。它正在做它应该做的事情。

As the documentation for git stash save states, it will do a git reset --hard after saving your changes. It was the git reset --hard that overwrote the new file.txt. One might argue that git reset --hard should generate a warning if an untracked file will be overwritten, but I still wouldn't call this a bug. It's doing what it's supposed to do.

在这里理解的重要事情 - 以及为您节省了很多麻烦 - 是 git stash save 不保存未跟踪文件(并且可能不应该)。

The important thing to understand here -- and what would have saved you a lot of trouble -- is that git stash save does not save untracked files (and it probably shouldn't).

这篇关于奇怪的混帐案 - 混帐隐藏后面的Git隐藏申请丢失未提交的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆