TF: Checkin only selected files instead of all Pending changes while merging - tfs

Using tf.exe, the command line utility for TFS, I've automated the process of merging two branches using tf.exe in a batch file in simple steps:
TF Get... /Recursive
TF Merge... /Recursive
However, while checking in the changes, "TF Checkin" Dialog shows all the pending changes selected in the dialog whether using /Recursive or not.
What I want: To select only modified files in my selected folder instead of all the pending changes. Please note that this is a random thing, as I have 100's of files in my folders, so only files changed during Merge should be selected (definitely these would be modified ones).
Solution I expect: To create a separate Workspace for my automated merge process. This would isolate the checkin process and would select only the changes made through this Workspace.
Another Possibility: Is it possible to Checkin files in a specific folder and ignore rest of the pending changes?
Thankx

I'm not sure I understand your problem right, but it is indeed possible to checkin only files in a specific folder. To avoid checkin problems you should probably do a "resolve" first. For instance
tf.exe get /r c:\src\branch1\project1 c:\src\branch2\project1
tf.exe merge c:\src\branch1\project1 c:\src\branch2\project1 /r /noprompt
tf.exe resolve c:\src\branch2\project1 /r /auto:acceptTheirs /noprompt
tf.exe checkin c:\src\branch2\project1 /r /noprompt /override:"done by script"
You should always do a /noprompt when running tf.exe from a script/automation process. This is to avoid popups. In the resolve I put /auto:acceptTheirs which will take the changes from the source branch when a conflicting change occurs. There are several different options here, you will have to concider which suits your purpose. /override on the checkin will override any checkin policies, which is probably (but not necessarily) a good idea from a script.
The approach with creating new workspaces every time is something I would try to avoid if possible. Creating and deleting a workspace is a heavy process, and in my experience it is difficult to keep track of all the workspaces so I usually end up with lots and lots of unused workspaces that needs to be removed.

Just discovered that we can also use Repository Address instead of hard-coding paths:
tf checkin $/MainRep/Playground/MyFolder/HTMLLogViewer /r
Would give same facility and would prevent us from using hard coded paths.

Related

Checkin multiple files with tf.exe in one changeset

On one of our builds we are kicking off some automated process which is checking out and checking in some files automatically.
This all works rather well, but at this time we are running the checkin command which looks like the following
tf.exe checkin /force /comment:"foo" /noprompt /bypass /override:"bar"
All of the files with a Pending status will get checked in.
I'd like to make this script a bit more specific and only checkin the files (2 in total) which we actually change during the build, so we know for sure no files will get checked in 'by accident'.
I've already seen we can specify a single filename with the checkin command, but doing so we will get 2 different changesets in TFS, instead of 1. We would really like to have 1 changeset, containing both changed files as the changes belong to eachother.
Any ideas on how to approach this?
Minor addition / Short term solution
For the moment I've solved our 'problem' by specifying the folder where our modified files are located, which kind of looks like this
tf.exe checkin "/my/folder/location/" /recurse /force /comment:"foo" /noprompt /bypass /override:"bar"
Note the folder location and the /recurse parameter added.
You simply separate the files by spaces:
tf.exe checkin file1.ext file2.ext /force /Comment:"foo" /noprompt /bypass /override:"bar"
The documentation is not clear about this point but it might be a general specification of an itemspec that it can be multiple items.
See similar question about checkout: Is there a way to check-out multiple files from various folders in TFS in a single operation
As mentioned by others you might run into problems with the command line being longer than the system supports, in which case you might need to look at other solutions.
cmd.exe has a limit on how long a command can be. Using the version control API, or simply 'tf checkin /i' (no arguments) is likely to be a better choice than passing lots of long filenames.
It's normal if a file becomes automatically checked out due to a change, and if ultimately the contents of the file are changed back to it's original state. At that point you would see the message about identical contents upon comparison. You could also use tfpt uu /noget /r * command to ignore Files which are identical to the originals. You'll need to have TFS Power Tools installed for this to work. Note: there is no TFS Power tool 2017.
For more details please refer below two links:
Visual Studio TFS shows unchanged files in the list of pending changes
Can TFS Pending Changes show files that are truly changed like SourceGear Vault?

How to handle missing 'added' files during check-in

I have a bunch of files in the 'added' state across many folders that were accidentally deleted from the file system. How can I easily either undo them or convert all of them to a 'delete' status? I'd prefer not to have to manually undo each file one at a time.
What I've tried so far:
In the Pending Changes window, using the Undo command for each missing file is tedious. Since the window does not identify which files are missing, I have to compare this window to the file explorer and compare the contents of each folder.
The answers for this similar question don't apply to me because my files are in the 'added' state, so comparing my workspace to the server will not identify these missing files.
I've looked through the TFS Power Tools for something to identify missing files but haven't found anything that directly addresses missing files.
The tfpt online command doesn't address missing files in the 'added' state.
If I read you correctly, in this case your underlying file system and what TFS thinks is on your file system have gotten out of sync.
The best, easiest, way I know how to rectify this is to undo all your changes, then redo the adds, deletes, and edits that you actually require. I know that with many files this will be a pain, but let me reiterate: I mean the best, easiest way and not the fun, effortless way (which I don't think exists)!
Do a 'clean' in your project within Visual Studio, then delete any bin/ and obj/ folders in the source.
Then undo all changes for your project.
If you are using TFS < 2013, I would recommend the use of Team Foundation Power Tools online functionality. For instance:
cd \dev\path\to\project\root\
tfpt online /adds /diff /deletes /recursive .
Otherwise, if you are using TFS 2013, then you can use the built-in 'reconcile' functionality (cannot find a web URL for this, the 2010 docs are incorrect, use 'tf reconcile /?' for a description):
cd \dev\path\to\project\root\
tf reconcile /adds /deletes /diff /recursive /noignore /promote .
With TFS Power Tools installed, run this command from a VS command prompt in the appropriate folder:
tf reconcile /deletes /diff /recursive /noignore /promote
This will display a list of pending changes. The missing files will all be selected with a new status of 'delete'. Click Promote to save the change, then try again to check in.
This is a slight variation of d3r3kk's answer but without the /add flag which causes more files to be selected than necessary.

tf.exe undo pending changes from other users

I am looking to migrate our TFS projects to another server. Before doing this I want to inspect all pending changes, undo them (or tell the person that has it checked out what it's all about) and lock the project on the old server.
For this I need to undo checkouts in very old workspaces that no longer exist. I'm now looking for ways to make this work. I realise there are a bunch of other questions like this, most with answers that point towards using tf.exe, which I am also using, but there's one thing that I just can't seem to get my head around.
Here's the deal. I'm using the following command to check to see if there's still files checked out by anyone.
tf status "$/MyProject" /s:MyServer /u:* /recursive
This presents me with a list of all files that are checked out and by whom. To undo the checkout I can now use this command:
tf undo /workspace:"TheWorkspace";TheUser
$/MyProject" /server:MyServer /recursive
This is all very nice, but notice how I need the workspace name to make this work. This name is however not returned by the tf status command. So now I'm forced to mess around with the workspaces command to figure out which workspaces a user has like this:
tf workspaces /server:MyServer /owner:TheUser /format:detailed
There has to be another way right? This way I'm just looking through a massive report on workspaces for each user (some have had as many as 6 computers/laptops over the years, all with dozens of workspaces), it's no fun :(
Is there any way to make tf status report the workspace name as well? Or make the undo command work across workspaces?
Any help would be appreciated.
tf status supports a /format parameter. The brief output (which is the default) doesn't include the workspace. the detailed one does.
tf status "$/MyProject" /s:MyServer /u:* /recursive /format:detailed

Multiple copies of a solution on one user/machine with TFS 2010

Is there a way to pull two copies of a single solution from TFS 2010 for the same user/machine?
You can have multiple copies of a single solution either by having multiple branches in TFS or by setting up different workspaces.
The branches are good for when you need to be able to check in code for both copies of the solution, and have other people work with it too.
I use the multiple workspaces when I need to have a last good state of the code on my dev box while at the same time and still working on new features.
Sean L's answer is correct.
My addition is that I coded up some command line calls to do it.
Makes the "What exactly is going on here" stuff a little clearer, IMHO.
Put the below in .bat file. And save it to c:\ (anywhere you want)......if your BASEDIRECTORY is set to c:\ (somewhere) (or match the drive letters).
set __MYWORKSPACENAME=MySuperCoolNewWorkSpaceName001
set __BASEDIRECTORY=c:\tfsstuff\
MD %__BASEDIRECTORY%
CD %__BASEDIRECTORY%
set __tfExe=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe
"%__tfExe%" workspace /new %__MYWORKSPACENAME% /collection:http://myteamfoundationserver:8080/tfs/my_super_cool_projects /noprompt
"%__tfExe%" workfold /map $/MyBranch %__BASEDIRECTORY%\MyBranch
"%__tfExe%" get %__BASEDIRECTORY%\MyBranch\ /recursive /noprompt
set __BASEDIRECTORY=
set __MYWORKSPACENAME=
set __tfExe=

Comparing differences in an entrie workspace in TFS

As TFS maintains an idea of the version that is downloaded on the client, such that "Get Latest" might not get the latest version; I was wondering if there was an easy way to report differences across an entire workspace?
I only ask as a member of my team is leaving immanently, and our IT department need to recycle his laptop very quickly, and I'm a little concerned that there is potential for some changes not to have been changed in.
Sorry misread the question.
If you have proper checkouts you can just do the following:
Go to the command line, and at the top if the workspace type
tf checkin . /recursive
This will present the what's outstanding in the workspace.
Or just shelve the lot to the serve and then you can peruse at leisure.
tf shelve
Oherwise the other thing I would do is
Just get the latest version of the software to another Directory and then use the excellent beyond compare tool from scootersoft to compare the directories recursively.
Once you have the files just copy the list to a bat file calling tf checkout on each one.
Then do tf shelve.

Resources