📅  最后修改于: 2023-12-03 15:00:57.839000             🧑  作者: Mango
当我们在 Git 项目中忽略了某些文件后,如果在本地修改了这些被忽略的文件,它们不会被 Git 跟踪并提交到远程仓库。但是有时候情况会有些特殊,我们需要查看这些被忽略的文件是否被修改过。在这种情况下,我们可以使用 git status
命令来显示被忽略的文件已修改。
$ git status --ignored
--ignored
参数:显示被忽略的文件是否被修改的状态。在项目目录下新建一个被忽略的文件 ignored.txt
$ touch ignored.txt
$ echo "This file should be ignored." >> ignored.txt
$ echo "ignored.txt" >> .gitignore
运行 git status
命令
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
此时 Git 不会显示被忽略的文件 ignored.txt
。
修改被忽略的文件 ignored.txt
$ echo "This file has been modified." >> ignored.txt
运行 git status --ignored
命令
$ git status --ignored
On branch main
Your branch is up to date with 'origin/main'.
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)
modified: ignored.txt
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
此时 Git 就会显示被忽略的文件 ignored.txt
已经被修改过了。
git status --ignored
命令可以让我们在 Git 项目中查看被忽略的文件是否被修改过,方便我们及时修复问题。