Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的服务器和计算机上有一个名为“myfile.php”的文件。 我想从 git index 中删除 myfile.php 以防止更改服务器中的 myfile.php。我通过将文件添加到 .gitignore 并使用“git rm --chached myfile.php”从索引中删除文件来做到这一点 现在什么时候我运行“git pull”它会从服务器的工作目录中删除文件本身,但我想将它保留在服务器上并保持它不被更改。有什么问题?
如果您不小心将要从索引中删除的文件(但不是从 git 的历史记录中删除)添加到索引中,请使用:
git reset HEAD <file>
此外,您可以注意到,当您执行 时git status,git 实际上会告诉您:
git status
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: my_file # $