Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

git - Ignore a file from future commits but leave that on repo

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:

  1. add the file path into .gitignore
  2. As it was committed initially into the repo I need to remove it from being a tracked file so: git rm --cached <file>

However will step also remove from the repo? How do I therefore handle this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

But I think there are better solutions. This one needs every developer to be aware not to commit the changes of sitemap.xml.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...