从以后的提交中忽略文件,但将其保留在回购中 [英] Ignore a file from future commits but leave that on repo
问题描述
我有我的sitemap.xml文件要保留在存储库中(因为它会不断更新),但是在以后的任何代码提交中都将其忽略(因为我不希望覆盖它).
I have my sitemap.xml file that I want to leave on the repository (as it is continually updated) however ignore it from any future code commits (as I don't want it to be overwritten).
要做到这一点-从我的阅读中,我需要:
So to do this - from my reading I need to:
- 将文件路径添加到
.gitignore
- 已承诺最初进入回购协议,我需要将其从跟踪中移除这样的文件:
git rm --cached< file>
不过,步骤也会从存储库中删除吗?因此,我该如何处理呢?
However will step also remove from the repo? How do I therefore handle this?
推荐答案
一种可能的解决方案是在 pre-commit
挂钩中添加 git reset HEAD-sitemap.xml
.如有必要,可以在 git commit
时通过 -n
绕过此钩子.在服务器端,需要一个挂钩来拒绝任何包含sitemap.xml更改的提交.
One possible solution is to add git reset HEAD -- sitemap.xml
in pre-commit
hook. This hook can be bypassed via -n
when git commit
if necessary. And in the server side, a hook is needed to reject any commit that includes changes of sitemap.xml.
但是我认为有更好的解决方案.这需要每个开发人员注意不要提交sitemap.xml的更改.
But I think there are better solutions. This one needs every developer to be aware not to commit the changes of sitemap.xml.
这篇关于从以后的提交中忽略文件,但将其保留在回购中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!