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

发布于 2024-10-04 15:19:25 字数 204 浏览 8 评论 0原文

如何从我的 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 技术交流群。

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

发布评论

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

评论(8

红墙和绿瓦 2024-10-11 15:19:25

这也会添加删除。

git add -u .

检查要提交的内容:

git status

This will add deletes as well.

git add -u .

Check what's staged to be committed with:

git status
桃气十足 2024-10-11 15:19:25

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

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

  1. 通过恢复索引中的版本来取消删除它们: git checkout path/to /folder
  2. 在 Git 中将它们标记为已删除,然后提交: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:

  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
三生池水覆流年 2024-10-11 15:19:25

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

走走停停 2024-10-11 15:19:25

您需要记录它们确实要被删除。与记录文件更改的方式相同。

您将使用 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 use git rm.

病女 2024-10-11 15:19:25

您需要告诉 git 它已被删除

git rm folder

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

you need to tell git that it is removed

git rm folder

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

莫相离 2024-10-11 15:19:25

当我从 upstream/master 获取 pull 时,我也删除了红色文件。我尝试了不同的方法,但没有任何效果。
最终,我不得不恢复我的分叉分支的所有更改(已提交、暂存、未暂存),并且必须将我的存储库与上游主分支重新同步。

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

I was also having red colored deleted files when I took pull from 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.

git reset --hard upstream/master
git pull upstream master
清风疏影 2024-10-11 15:19:25

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

使用命令:

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

柠北森屋 2024-10-11 15:19:25

在我“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.

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