Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git:如何删除现在在gitignore中但以前添加到repo中的文件_Git_Github_Gitignore - Fatal编程技术网

Git:如何删除现在在gitignore中但以前添加到repo中的文件

Git:如何删除现在在gitignore中但以前添加到repo中的文件,git,github,gitignore,Git,Github,Gitignore,我有几个文件在repo和.gitignore中 我希望当我执行git pull origin master时,这些文件将从repo中删除,但不会从我的生产服务器中删除 我尝试了多种解决方案,但都没有成功,在每种解决方案中,我都会在执行拉取操作时从服务器上删除文件 参考资料: 好的,没有办法用“停止跟踪此文件,但保留现有版本”标志来标记文件路径 在部署包括删除文件的第一个版本时,您需要执行一个手动操作 比如: cp file file.prod git pull mv file.prod fi

我有几个文件在repo和.gitignore中

我希望当我执行git pull origin master时,这些文件将从repo中删除,但不会从我的生产服务器中删除

我尝试了多种解决方案,但都没有成功,在每种解决方案中,我都会在执行拉取操作时从服务器上删除文件

参考资料:


好的,没有办法用“停止跟踪此文件,但保留现有版本”标志来标记文件路径

在部署包括删除文件的第一个版本时,您需要执行一个手动操作

比如:

cp file file.prod
git pull
mv file.prod file

首先需要
git filter branch
,然后要求每个人重新设置根据旧历史创建的分支的基础

参考:

这很复杂,可能会引起问题,所以下次要小心,不要到那个里


如果你因为某种原因不能做到这一点,那么需要等到时间机器发明:)

这是我看到的第一个答案(经过数小时的搜索)这似乎解决了我关于
git filter分支的问题--force--index filter'git rm--cached--ignore unmatch*.ext'--prune empty--tag name filter cat--all
——特别是,尽管有
--cached
标志,这个命令也会删除头部的文件。我不明白为什么
git-rm--cached
只保留HEAD,而
git-filter分支--index-filter'git-rm--cached…
命令没有。