Git状态错误地指出文件已删除 [英] Git status incorrectly saying files are deleted

查看:43
本文介绍了Git状态错误地指出文件已删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了一个存储库,并在其中编辑了一个文件 tip.php ,然后使用 git add 将其添加了.但是当我下次运行 git status 时,我得到以下信息:

I cloned a repository and edited exactly one file in it, tip.php, and then added it using git add. But when I next run git status I get the following:

$ git status
On branch removeRatings
Changes to be committed:
 (use "git reset HEAD <file>..." to unstage)

 deleted: .htaccess
 deleted: COPYRIGHT.txt
 modified: tip.php

即使 .htaccess COPYRIGHT.txt 都没有被删除,因为我可以在目录中看到它们.有人有理由会发生这种情况吗?我正在Windows 8上运行Git Bash.

Even though neither .htaccess or COPYRIGHT.txt was deleted, as I can see them right in the directory. Anyone have a reason why this would happen? I'm running Git Bash on Windows 8.

推荐答案

此消息表示文件(或文件删除)已添加到阶段.

This message means that files (or file removals) were added to stage.

运行以下命令.

 git add --all
 git status

现在,您应该查看它们是否已被移动/重命名或被删除.我想它们是通过某种方式移动的,也许是通过您的IDE来实现的.

Now you should see whether they were moved/renamed or just deleted. I suppose that they were moved in some way, maybe by your IDE.

git reset .htaccess
git reset COPYRIGHT.txt
git status

现在状态应该是清除的,并且仅显示您的 tip.php .但是,如果现在您在未跟踪的文件中看到 .htaccess COPYRIGHT.txt`,则自上次提交以来,这些文件已被更改.

Now the status should be clear and show only your tip.php. But if you now see .htaccess and COPYRIGHT.txt` in the untracked files, then these files have been changed since the last commit.

如果您确定没有更改或删除它们并且不想保存更改:

If you're sure that you didn't change or delete them and do not want to save changes:

git reset --hard .htaccess
git reset --hard COPYRIGHT.txt

这会将这些文件重置为上一次提交的状态.注意,不要在没有参数的情况下运行 git reset --hard ,因为它会完全删除您未提交的更改.

This will reset these files to the state of last commit. Be careful and don't run git reset --hard without an argument, as it would completely delete your uncommited changes.

这篇关于Git状态错误地指出文件已删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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