从 git index 中删除文件也会从服务器中删除该文件

发布于 2024-09-25 20:07:56 字数 236 浏览 0 评论 0原文

我的服务器和计算机上有一个名为“myfile.php”的文件。
我想从 git index 中删除 myfile.php 以防止更改服务器中的 myfile.php。我通过将文件添加到 .gitignore 并使用“git rm --chached myfile.php”从索引中删除文件来做到这一点
现在,当我运行“git pull”时,它会从服务器的工作目录中删除文件本身,但我想将其保留在服务器上,并确保其安全不被更改。 有什么问题吗?

I have a file named "myfile.php" on my server and in my computer.
I want to remove myfile.php from git index in order to prevent changing myfile.php in server.I do this by adding the file to .gitignore and removing the file from index with "git rm --chached myfile.php"
Now when I run "git pull" it removes the file itself from working directory in server but I want to keep it on the server and just keeping it safe from changing.
What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果你不小心在索引中添加了一个你想要从索引中删除的文件(但不是从 git 的历史记录中删除),那么使用:

git reset HEAD <file>

另外,你可以注意到,当你执行 git status 时,git 实际上会告诉你这个:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   my_file
#
$

If you accidentally added to the index a file you want to remove from the index (but not delete from git's history) then use:

git reset HEAD <file>

Also, you can note that when you execute git status, git will actually tell you this:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   my_file
#
$
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文