We use tortoise hg with Kiln. 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. For eg., say in a login screen I may hard code the userid, password for testing. 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. Any trick in tortoise hg to ignore files that are part of the repo ? (so they do not show up as modified (M) during a commit.) thanks
4 Answers
I always use a combination of .hgignore and BeforeBuild
(in the .csproj file) for things like this.
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.example
is identical, but with fake data like "dummy_user" and "dummy_pw".
App.config
is not part of the repository, and it's ignored (in .hgignore
).
App.config.example
is part of the repository.
Then, I have the following in the BeforeBuild
target in the .csproj file of my solution:
<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 createdApp.config
file). - 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 ifApp.config
does not already exist
![](../../users/profiles/6884.webp)
- 33,837
- 14
- 123
- 176
The answer by Christian is the right one, but I want to mention that TortoiseHg supports what you want with their Auto Exclude List.
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.
![](../../users/profiles/1000551.webp)
- 7,103
- 8
- 44
- 57
![](../../users/profiles/110204.webp)
- 69,865
- 23
- 162
- 224
-
Does it support wildcards? A simple test indicates that it doesn't and I need to list out every file by name but I wanted to make sure I'm not missing something. – Ben Oct 29 '15 at 14:18
When you do a TortoiseHG commit, there is a list of files with checkboxes by them. 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.
![](../../users/profiles/26227.webp)
- 37,919
- 28
- 110
- 204
-
Yes. Thats what I do right now but sometimes I forget to uncheck that box you mention since the file I do not want committed is buried in the middle of whole bunch of files I want committed -- and hence this question :-). thanks – Gullu Sep 08 '11 at 16:17
-
@Gullu: I have found the command line the best approach for more complicated operations in hg. I would suggest a "safecommit.bat" file which excludes the files that have the sensitive data. – Paul Nathan Sep 08 '11 at 16:22
-
ok. If nothing else works I will venture into the dark side (command line). thanks – Gullu Sep 08 '11 at 16:24