How to Remove Files Deleted from OS but Not Git
You can use the git status command to see the files that are not removed by Git but deleted from the OS directly. The output of the command will show the deleted files under the 'deleted' section:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: file1.txt
deleted: file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
In this example, 'file1.txt' and 'file2.txt' were deleted from the OS directly, and Git has detected the changes as 'deleted' but not staged for commit. To remove these files from Git as well, you can use the git rm command:
$ git rm file1.txt file2.txt
rm 'file1.txt'
rm 'file2.txt'
After running this command, Git will stage the removal of these files, and you can commit the changes with git commit.
原文地址: https://www.cveoy.top/t/topic/nCNP 著作权归作者所有。请勿转载和采集!