当我运行 git status 时:
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
# modified: .project
# modified: reports/images/2014-03.png
# modified: reports/images/graph-2014-03.bmp
# deleted: reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293161.bmp
# deleted: reports/phpbmp/cache/0/02/027/0270/phpThumb_cache_portal.gep.co.za_src02707010e1e50bc80594
f31460d514c4_par80d8993b181666aca11d7be02b12fea7_dat1399293182.bmp
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.MD
# reports/phpbmp/cache/9/
no changes added to commit (use "git add" and/or "git commit -a")
我意识到我不希望跟踪对以下文件的更改:
.project
reports/images/*.png
reports/images/*.bmp
reports/phpbmp/cache/*
所以我将这些文件添加到
.gitignore
如何从当前工作目录中删除
Changes not staged for commit
下的文件?
如果我理解得很好,你希望
filename
位于 git 存储库中。但是,您不希望收到有关 filename
的新更改的通知。您可以使用以下命令来执行此操作:
git update-index --assume-unchanged <filename>
如果您想再次开始跟踪更改,请运行以下命令:
git update-index --no-assume-unchanged <filename>
附加信息:编辑 .gitignore 只会忽略文件,因此它们不会被添加到 git 存储库中。但是,已经跟踪的文件不会被忽略。
文件已被跟踪,现在您想忽略这些文件。
git rm --cached filename
echo "filename" >> .gitignore
git add .gitignore
git commit -m 'Removes filename file and adds it to gitignore.'