68

There is one file that I always made changes to, but that I never want to be checked in. I would like TFS to block me from ever checking it in or committing the changes. How can I configure TFS to do this?

Details: There is another developer on the project that has checked in some bad code that I prefer to comment out on my local machine. Since they are a client, I prefer to keep this a technical exercise rather than make it a political one.

MedicineMan
  • 15,008
  • 32
  • 101
  • 146

8 Answers8

91

One of TFS undervalued features is cloaking. Like SVN's ignore, cloaking will let you ignore a certain folder or files.

Cloaking a Folder

Cloaking a folder is easy: just right click a folder on the source control explorer and select Cloak

Cloaking a File

The UI doesn't expose cloaking on a single file, but sometimes you may want to cloak a certain file like app.config.

  1. Go to File > Source Control > Workspaces

  2. Select your workspace and click Edit.

  3. Under the working folders, and a new entry with status Cloaked and enter the full server path of the file you want to cloak. (E.g.: $/MyTeamProject/Dev/Src/SomeProject/app.config)

Cloaking a file


Using Local Workspace .tfignore file (In TFS 2012, 2013, 2015 and up)

In Local Workspace, use you can use .tfignore file (the equivalent of .gitignore for Git)

.tfignore file example
 ######################################
# Ignore .cpp files in the ProjA sub-folder and all its subfolders
ProjA\*.cpp
# 
# Ignore .txt files in this folder 
\*.txt
#
# Ignore .xml files in this folder and all its sub-folders
*.xml
#
# Ignore all files in the Temp sub-folder
\Temp
#
# Do not ignore .dll files in this folder nor in any of its sub-folders
!*.dll

Blocking by Permissions

Another approach is deny check-in on the file (requires administrative privileges):

  1. Right click the file > click Properties > Security

  2. Add your user and mark Deny on the Check In permission.

Deny Check In

KMoraz
  • 14,004
  • 3
  • 49
  • 82
12

For TFS 2012, just use the .tfignore file.

When you add ignored files to folders that are mapped in a local workspace, they do not appear in the Pending Changes page in Team Explorer.

http://msdn.microsoft.com/en-us/library/ms245454.aspx

Androiderson
  • 16,865
  • 6
  • 62
  • 72
  • 3
    How in the name of !@#$%@ do I create a file named ".tfignore" ? That's an illegal file name in Windows. – Scott Baker Dec 19 '13 at 21:42
  • 1
    @ScottSEA There are a fews ways: notepad (save as type = all files), rename using command prompt (command `ren`) etc just don't use the explorer. – Androiderson Dec 20 '13 at 00:33
  • I discovered that, at least for me, .tfignore didn't work in VS2013 until after it was checked in. Also I used `move` in cmd shell to rename it. – Josh Jan 07 '15 at 15:25
  • 5
    you can name the file ".tfignore." in windows explorer. notice the extra "." at the end. Explorer will rename the file to ".tfignore" – Patrick Huber Feb 11 '15 at 20:28
9

Visual Studio 2013 (and 2012)

This feature is available by selecting the file(s) and going to:

File > Source Control > Advanced > Exclude ... from Source Control
Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
  • 1
    No, this option is NOT available in VS2012. – Paul Dec 09 '14 at 12:00
  • 2
    I don't see this option in VS 2013.4 – Hooch Mar 09 '15 at 21:39
  • 1
    Thanks its there for me, note don't right click on the file but go to the file menu on the top left of the visual studio window. – Xander Jun 13 '16 at 14:35
  • 1
    The option is context sensitive. The file you want to exclude has to be the open current window in Visual Studio for the File menu to gain the option to exclude the file. – Shiv Mar 06 '17 at 06:06
4

You can just exclude the file from Source Control

1. Select the file in Solution Explorer

2. Go to File -> Source Control -> Advanced

Path To Exclude

and here it is

Here is the Exclude

Felix Keil
  • 2,344
  • 1
  • 25
  • 27
  • The option "Exclude EndPointConfiguration.config..." is not available in VS2012 - at least not on my VS2012 Professional installation. – Paul Dec 09 '14 at 12:02
  • This is VS2012 Pro. It should be there. "EndPointConfiguration.config" is just the name of the file that is selected in the Solution Explorer. So there should be a "Exclude xxxx from Source Control". And you have to go over the Menu! It's not available if you just right click the file! – Felix Keil Dec 09 '14 at 12:48
  • Felix, I've retried. My VS2012 Professional installation displays the following items in the menu selector File | Source Control | Advanced: 1. Get specific Version of -file- 2. Lock 3. Apply Label 4. Resume Conflict Resolution 5. Open from Source Control 6. Add Project from Source Control 7. Workspaces 8. Change Source Control 9. Refresh Status – Paul Dec 10 '14 at 06:37
  • 2
    Does this change propagates to all use users on the same project or just to local work-space? – dotsa Mar 06 '15 at 20:30
  • How is this answer different from the one posted by Evan Mulawski seven months earlier? – Aaroninus Apr 07 '17 at 14:39
  • @Aaroninus Pictures, that explicitly explain the process. Especially to prevent the error to just right click the file – Felix Keil Apr 07 '17 at 18:09
3

There are 2 ways.

  1. You can "Uncheck" it in the "Pending Changes" window, it should then remember this next time you load Visual Studio. This is a bit cumbersome if you like to "select all" and Check/Uncheck the items in the list and prone to error.
  2. Don't "check-out" the file, go into Explorer and remove the Read-Only attribute yourself. Then edit the bits you want. The caveat is, that TFS doesn't know about it and doesn't always update the file correctly. Also, if you edit that file in VS (for anoter change), it will be "checked out" and you may then check it in by mistake.

I don't like either option in TFS / VS 2010, so I actually avoided doing this (I used to have a large "ignore-on-commit" when we used SVN). Now I am using VS11 Beta, the Excluded list does exactly what I want, I move something to it and it stays there, and I can easily put other changes on and off that list and not checkin that file.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
2

if you are using "Local" workspace type, that is new to TFS 2012 - your source-controlled files are not set "read-only" at all. But in this case no matter where you edit them, they are seen by TFS as changed and included into pending changes. Would be great to have option like "auto-exclude" from pending changes by default. And include them only when you want this.

Anik
  • 53
  • 6
2

Another option is using a custom check-in-policy. You can build your own or use Forbidden Patterns Policy from the TFS 2010 Power Tools. Of course you would need to be an TFS admin to install it and it might not be the thing you want in your situation. Also any check-in-policies can be overridden.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
1

Hidden Folders never gets detected as a change by TFS use this feature if you are using VS2010. The folder that you don't want to be a part of TFS Mark it as hidden.

Sandeep
  • 615
  • 6
  • 13