提交后 Git 仍然显示已删除的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4307728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:33:35  来源:igfitidea点击:

Git still showing deleted files after a commit

gitgit-commit

提问by Nik So

How can I remove deleted files from my Git repo?

如何从我的 Git 存储库中删除已删除的文件?

I've deleted a folder of a JavaScript library, which contained many files. I then went to commit the changes like so:

我删除了一个 JavaScript 库的文件夹,其中包含许多文件。然后我去提交更改,如下所示:

git add .
git commit "message"
git status

But it shows all those files as "deleted ....".

但它将所有这些文件显示为“已删除....”。

How can I make them go away?

我怎样才能让它们消失?

采纳答案by cdhowie

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

如果它列出了“待提交”部分下的文件,则继续提交;文件将保持删除状态。(Git 也会跟踪删除,而不仅仅是更改。)

If it lists the files under the "changed but not updated" section, then you have two options:

如果它列出了“已更改但未更新”部分下的文件,那么您有两个选择:

  1. Undelete them by restoring the version in the index: git checkout path/to/folder
  2. Mark them deleted in Git, then commit: git rm -r path/to/folder
  1. 通过恢复索引中的版本来取消删除它们: git checkout path/to/folder
  2. 在 Git 中将它们标记为已删除,然后提交: git rm -r path/to/folder

回答by Jamund Ferguson

This will add deletes as well.

这也会添加删除。

git add -u .

Check what's staged to be committed with:

检查要提交的内容:

git status

回答by mateostabio

git add -u .

git add -u .

If you type git statusand the result says up to date, but in red it says

如果您输入git status并且结果显示为最新,但显示为红色

deleted: folder/example0.jpg
deleted: folder/example1.jpg
deleted: folder/example2.jpg

删除:文件夹/example0.jpg
删除:文件夹/example1.jpg
删除:文件夹/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 uand the period

您需要输入它才能永久删除它,git add -u .然后所有红色文本都将标记为绿色。

**** 不要忘记字母u句点之间的空格

回答by ?imon Tóth

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 use git rm.

只是代替git add,您将使用git rm.

回答by mpapis

you need to tell git that it is removed

你需要告诉 git 它已被删除

git rm folder

or if you do not want to keep them in repo you can add them to .gitignore

或者如果您不想将它们保留在 repo 中,您可以将它们添加到 .gitignore

回答by user3572157

supposing say you want to remove a file and would not want it to be committed:

假设你想删除一个文件并且不希望它被提交:

use the command:

使用命令:

git reset HEAD filename

git reset HEAD 文件名

and then do a git statusto verify if the file to be removed is not appearing

然后做一个git status来验证要删除的文件是否没有出现

then do a git commit

然后做一个git commit

回答by RyanShao

i find myself have an unexpected 'deleted' folder after i 'rm xxx' to delete some local file.

在我“rm xxx”删除一些本地文件后,我发现自己有一个意外的“已删除”文件夹。

i first create an temp branch and commit the unwant 'deleted' folder and then delete that temp branch.

我首先创建一个临时分支并提交不需要的“已删除”文件夹,然后删除该临时分支。

回答by JerryGoyal

I was also having red colored deleted files when I took pullfrom upstream/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.

当我pullupstream/master. 我尝试了不同的东西,但没有任何效果。
最终,我不得不为我的分叉分支恢复所有更改(已提交、已暂存、未暂存),并且必须将我的 repo 与上游主分支重新同步。

git reset --hard upstream/master
git pull upstream master