Git 在提交后仍然显示已删除的文件
如何从我的 Git 存储库中删除已删除的文件?
我删除了 JavaScript 库的一个文件夹,其中包含许多文件。然后我像这样提交更改:
git add .
git commit "message"
git status
但它显示所有这些文件为“已删除......”。
我怎样才能让他们消失呢?
How can I remove deleted files from my Git repo?
I've deleted a folder of a JavaScript library, which contained many files. I then went to commit the changes like so:
git add .
git commit "message"
git status
But it shows all those files as "deleted ....".
How can I make them go away?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这也会添加删除。
检查要提交的内容:
This will add deletes as well.
Check what's staged to be committed with:
如果它在“待提交”部分列出了文件,则只需继续提交即可;文件将保持删除状态。 (Git 也跟踪删除,而不仅仅是更改。)
如果它列出了“已更改但未更新”部分下的文件,那么您有两个选择:
git checkout path/to /folder
git rm -r path/to/folder
If it lists the files under the "to be committed" section, then just proceed with the commit; the files will remain deleted. (Git tracks deletions too, not just changes.)
If it lists the files under the "changed but not updated" section, then you have two options:
git checkout path/to/folder
git rm -r path/to/folder
git add -u .
如果您输入 git status,结果显示最新,但以红色显示
已删除:文件夹/example0.jpg
已删除:文件夹/example1.jpg
已删除:folder/example2.jpg
您需要输入此内容才能永久删除
git add -u .
那么所有的红色文本将被标记为绿色。
**** 不要忘记字母u和句点之间的空格
git add -u .
If you type git status and the result says up to date, but in red it says
deleted: folder/example0.jpg
deleted: folder/example1.jpg
deleted: folder/example2.jpg
You need to enter this for it to be removed permanently
git add -u .
then all the red text will be marked in green.
**** Dont forget the space between the letter u and the period
您需要记录它们确实要被删除。与记录文件更改的方式相同。
您将使用
git rm
来代替git add
。You need to record that they are indeed meant to be deleted. The same way you record file changes.
Just instead of
git add
, you will usegit rm
.您需要告诉 git 它已被删除
,或者如果您不想将它们保留在存储库中,您可以将它们添加到 .gitignore
you need to tell git that it is removed
or if you do not want to keep them in repo you can add them to .gitignore
当我从
upstream/master
获取pull
时,我也删除了红色文件。我尝试了不同的方法,但没有任何效果。最终,我不得不恢复我的分叉分支的所有更改(已提交、暂存、未暂存),并且必须将我的存储库与上游主分支重新同步。
I was also having red colored deleted files when I took
pull
fromupstream/master
. I tried different things but nothing worked.Eventually, I had to revert all changes (committed, staged, unstaged) for my forked branch and had to re-sync my repo with the upstream master branch.
假设你想删除一个文件并且不希望它被提交:
使用命令:
git reset HEAD filename
,然后执行git status来验证该文件是否要删除的内容没有出现
,然后执行 git commit
supposing say you want to remove a file and would not want it to be committed:
use the command:
git reset HEAD filename
and then do a git status to verify if the file to be removed is not appearing
then do a git commit
在我“rm xxx”删除一些本地文件后,我发现自己有一个意外的“已删除”文件夹。
我首先创建一个临时分支并提交不需要的“已删除”文件夹,然后删除该临时分支。
i find myself have an unexpected 'deleted' folder after i 'rm xxx' to delete some local file.
i first create an temp branch and commit the unwant 'deleted' folder and then delete that temp branch.