简体   繁体   English

如何使用tortoise hg“作为存储库的一部分”来忽略kiln / mercurial中的文件

[英]how to ignore files in kiln/mercurial using tortoise hg “that are part of the repository”

We use tortoise hg with Kiln. 我们用窑龟用hg。 In my vs 2010 c# project there are some files that are part of the repository but I would like tortoise hg to ignore them when I make a commit. 在我的vs 2010 c#项目中,有一些文件是存储库的一部分但是我想在我提交时忽略它们。 For eg., say in a login screen I may hard code the userid, password for testing. 例如,在登录屏幕中,我可以硬编码用户ID,密码用于测试。 I dont really want this file considered during a commit. 我真的不希望在提交期间考虑此文件。 I understand .hgignore file but this really works for files that are not part of the repo. 我理解.hgignore文件,但这确实适用于不属于repo的文件。 Any trick in tortoise hg to ignore files that are part of the repo ? 在togise 中有什么技巧可以忽略属于repo的文件 (so they do not show up as modified (M) during a commit.) thanks (因此在提交期间它们不会显示为已修改的(M)。)谢谢

I always use a combination of .hgignore and BeforeBuild (in the .csproj file) for things like this. 对于像这样的事情,我总是使用.hgignore和BeforeBuild (在.csproj文件中)的组合。

In one of my pet projects, I have the following setup: 在我的一个宠物项目中,我有以下设置:

App.config contains my real hardcoded user id and password for testing. App.config包含我用于测试的真实硬编码用户ID和密码。
App.config.example is identical, but with fake data like "dummy_user" and "dummy_pw". App.config.example是相同的,但有假数据,如“dummy_user”和“dummy_pw”。

App.config is not part of the repository, and it's ignored (in .hgignore ). App.config 存储库的一部分它忽略(在.hgignore )。
App.config.example is part of the repository. App.config.example是存储库的一部分。

Then, I have the following in the BeforeBuild target in the .csproj file of my solution: 然后,我在解决方案的.csproj文件中的BeforeBuild目标中有以下内容:

<Target Name="BeforeBuild">
  <Copy
    Condition="!Exists('App.config')"
    SourceFiles="App.config.example" 
    DestinationFiles="App.config"/>
</Target>

All this together has the following effect: 所有这些一起具有以下效果:

  • the config file with the real data can never be accidentally committed to the repository, because it's ignored 具有真实数据的配置文件永远不会意外地提交到存储库,因为它被忽略了
  • the repository only contains the config file with the example data 存储库仅包含带有示例数据的配置文件
  • if someone else clones the repository to his machine, he won't have the "real" config file...but if it's missing, it will be automatically created before the first build by Visual Studio / MSBuild by simply copying the .example file (and then he can just put his real login data into the newly created App.config file). 如果有人将存储库克隆到他的机器上,他就不会有“真正的”配置文件...但是如果它丢失了,它将在Visual Studio / MSBuild首次构建之前通过简单地复制.example文件自动创建(然后他可以将真正的登录数据放入新创建的App.config文件中)。
  • if an App.config with real hardcoded user data already exists, it won't be overwritten when building because the BeforeBuild event will only happen if App.config does not already exist 如果App.config与真正的硬编码的用户数据已经存在,它不会被建立,因为如果BeforeBuild事件只会发生在覆盖App.config存在

The answer by Christian is the right one, but I want to mention that TortoiseHg supports what you want with their Auto Exclude List . Christian的答案是正确的,但我想提一下TortoiseHg通过他们的自动排除列表支持你想要的东西。

One problem with an exclude list is that it cannot work with merges: you must commit all files when you merge and so you'll have to do a little dance with shelve, merge, commit, and unshelve. 排除列表的一个问题是它无法使用合并:您必须在合并时提交所有文件,因此您必须与搁置,合并,提交和取消搁置进行一些跳舞。

When you do a TortoiseHG commit, there is a list of files with checkboxes by them. 当您执行TortoiseHG提交时,会有一个包含复选框的文件列表。 Deselect the files you do not want comitted. 取消选择您不想要的文件。

Or, on the command line, do a commit of the form hg commit --exclude "pattern" , where pattern is defined in the hg man page. 或者,在命令行上,执行提交形式hg commit --exclude "pattern" ,其中pattern在hg手册页中定义。

你可以随时使用hg忘记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM