如何从本地仓库中删除在远程仓库中删除的文件而不删除未跟踪的文件

How to delete files from local repo which were removed in remote repo without deleting untracked files

假设我的远程仓库中有以下文件

file_a.py
file_b.py

以及我同步的本地存储库中的以下文件

file_a.py
file_b.py
ignored_important_file.py

然后我从远程仓库中删除了 file_b.py,但是当我在本地计算机上执行 git pull origin master 时,我发现 file_b.py 仍然存在

我如何与删除 file_b 的远程仓库同步,​​但保留重要的忽略文件?

愚蠢的我!我在尝试 运行 git clean -f -n 时找到了答案。这应该删除所有过时的文件,但删除列表是空的。 但是 如果我 运行 git clean -f -n -x 其中 -x 强制它删除忽略的文件,我发现 file_b 在那里。 git 没问题,我错了。我的 .gitignore 文件看起来像这样

*.pyc
ignored_important_file.py

file_b.py 被删除了,但 file_b.pyc 保持不变。我将从 .gitignore 中删除 *.pyc,git 将为我清除所有剩余文件。