How to prevent ignored files from being removed?

只谈情不闲聊 提交于 2019-12-12 03:56:35

问题


I version controlled a project settings folder a couple months back on my default branch, and then over time created many branches off default. Now I've decided that I'd rather not have the project settings folder version controlled as it creates a lot of problems when switching between branches.

So I've hg forget'd this project settings folder which lets me keep the files on my local machine but removes them mercurial. However, when switching from one of the old branches which still have this folder versioned back to the default branch it actually removes the files from the local machine, which is bad.

How do I prevent that?

The folder is also in .hgignore on default now.


回答1:


It's impossible to do.

But the common practice is to keep config.ini.dist in your repository and build environment-specific config by some build-system right after you check source code out.




回答2:


The standard way to deal with this is to version control a template config file and ignore the real config file. The real config file can then include the template file, or maybe the template file is copied over once in a while.

The underlying reason for your problems is that running:

$ hg forget config.ini

is exactly the same as running:

$ hg remove config.ini
$ hg cat config.ini > config.ini

The forget command leaves the file behind in your working directory, but what you commit is still a file removal. This means that afterwards, Mercurial cannot distinguish between "file was forgotten" and "file was removed" — only the removal is committed, so the two commands look exactly the same.



来源:https://stackoverflow.com/questions/12046617/how-to-prevent-ignored-files-from-being-removed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!