How to track the branched history through tf command? - tfs

I know this can be achieved through IDE from this link How to Branch and keep the branch history with TFS 2013
However, I want to achieve this by tf command. I have tried tf history, not the wanted result.

You may need to use tf branchs command instead of tf history command which displays the history of a branch for a specified file or folder.
tf branches itemspec [/version:versionspec] [/collection:TeamProjectCollectionUrl] [/login:username,[password]]
More detail info, please refer to the link from MSDN: Branches Command

Related

How to determine folder vs branch with tf command?

I have this example where FolderA had sub FolderB and they were both folders, until I branched FolderB to FolderB-branch. Then both sub folder turned into branches.
How can I use tf command to determine what is folder and what is branch?
tf dir /r and tf dir /r /folders show the same info.
How can I use tf command to distinguish what is what?
TFS 11, Visual Studio 2012.
There is a way do this, using tf branches command. When using it, TFS returns 2 responses:
when item is a Folder:
Item FolderA is not used in any branch view
when item is a Branch, it lists branch tree, like:
../FolderB
>> ../FolderB-branch
Now we can parse the output and assign if item is a Folder or a Branch.
Of course, the command tf branches need to be run in parent folder or with full parameters like /collection and others, if required.

Let Jenkins build from multiple TFS repositories

I have a problem with Jenkins building my source code. I'm using a lib repo and a repo for my code. I want Jenkins to build the project if anything in one of the repos changes.
Does anyone has some pointer how to solve this? I managed to get it working in the case that everything is in only one repo, but I want to separate the lib and the project code.
Unfortunately,the TFS pluging for Jenkins currently does not support checking out the sources from multiple locations.
However, as a work around you could use the command line to create any sort of workspace that you like, and even copy a template workspace that you have lying around.
To achieved this use both TF and the powershell Snapin Microsoft.TeamFoundation.PowerShell.
Basically the workflow is as follows :
Get-TFsWorkspace (Powershell : To check for the workspace)
TF Workspace /new (To Create a workspace)
TF Workfold /unmap (use this to remove the default $/ mapping which is
made during workspace creation)
TF Workfold /map (To map specific locations, ie $/Repo/project)
TF Scorch (to remove any artifacts if there are any)
TF Get (To get the code)
More details please refer this answer in a similar question.

Why does tf merge /candidate doesn't show pending merges while Visual Studio does?

When I list my pending merges between Branch1 and Branch2 on Visual Studio it shows them. But If I use tf it doesn't.
The command I am using to list my pending merges with TF is:
tf merge /candidate Branch1 Branch2
And I get
There are no changes to merge.
Why is TF showing no pending merges?
I am using Visual Studio 2013 with TFS 2013.
You need to add the /recursive flag, otherwise tf merge will only compare the folders and will not check the child elements.
Of course you need to be in the workspace at the right location, to run the command.

Convert changeset(s) to shelveset

Is it possible to create a shelveset from the diff of two versions of one branch just by some operations in tfs/tfpt?
e.g. create a shelveset from (changeset 2013 -> changeset 2034)
It is possible to create a shelveset from a changeset with some limitations. I needed to rollback a change from a branch to remove it from a release but it wasn't in any other branch either so I wanted to keep the change in a shelveset. I achieved this as below:
Rollback the changeset and check in the rollback.
Rollback the rollback changeset. This gives me a set of pending changes containing the original change.
Shelve the pending changes.
You could apply this technique to the case described in the question but it would be a lot of manual effort as it would have to be repeated for every changeset. It would also generate a lot of mess in TFS as you would have to check in the rollbacks of the rollbacks too.
No, it's not possible. Changesets and shelvesets are different things, with different purposes. You could probably write a plugin to do what you're after (retrieve changeset, check out the files, shelve the files).
It's not impossible. Technically speaking you can do it, although you may not want to. I'll let the reader decide.
You may want to do this in a new workspace.
Get the Changeset in question (new code)
Move all the source to temp folder. (don't move the $tf folder). Source tree should now be empty.
Get the previous Changeset.
Mirror copy the new code on top of the old
Do a Reconcile.
Now you can create the Shelveset.
If you are able to focus to a particular folder, then it will go faster, and you can automate it. Here's example command lines that will do this. I just tried it and it worked for me.
In this example, I point to a folder from the root called "Src". Change it your root folder.
md tmpws
cd tmpws
tf vc workspace /new /noprompt tmpws /location:local /permission:private
tf vc get "$/Src" /version:C2222 /recursive /noprompt
cd ..
md tmp
move "tmpws\Src" tmp
cd tmpws
tf vc get "$/Src" /version:C1111 /recursive /noprompt /force /overwrite
cd ..
robocopy "tmp\Src" "tmpws\Src" /mir
tf vc reconcile /promote /adds /deletes /diff /recursive /noprompt
tf vc shelve /replace /noprompt mychange
tf vc undo "$/Src" /recursive /noprompt
tf vc workspace /delete tmpws
cd ..
rmdir /q /s tmp
rmdir /q /s tmpws
While this solution doesn't involve a pure TFS solution, it doesn't involve mucking with the TFS changeset history like Lee Richardson's answer does.
You can use Git-TFS to clone a TFS repository or branch, then create a new branch from a previous commit (TFS check-in), reapply changes from a newer commit and post that as a shelveset:
Look in the git log for the commit before the one you want to create a changeset for:
$ git log --oneline
AAAAAAA Newest commit
BBBBBBB The commit for which I want a shelveset
CCCCCCC The commit where I will create a new branch from
Create a new branch from the commit that occurs before the one you want to retroactively create the shelveset for:
$ git checkout -b CCCCCCC
Checkout the changes from the commit for which you want to create the shelveset for:
$ git checkout BBBBBBB -- .
Commit these staged files:
$ git commit -m "Committing stuff for a retroactive shelveset that does X, Y and Z."
Create the shelveset:
$ git tfs shelve my_retroactive_shelveset HEAD
Advantages
This keeps the TFS changeset history clean without requiring you to revert a changeset, create a shelveset to un-revert the previously reverted changeset.
Since the shelveset was created from a branch in Git, you can delete that branch and still keep your Git-TFS history clean as well.
Disadvantages
It's not a pure TFS solution
Each commit will create a shelveset. So we can find a shelveset created while the commit was initiated. That will have exact same changes. We dont need to create new shelveset.

Can I completely force a checkin to TFS?

I need a way to force a branch in TFS to update itself to exactly match what is in the working folders. I need something that will delete files that are on the server but not in the working folders, add files to the server that are only in the working folders, and update the changed files by using the exact version that is in the working folders. I need this to be form the command line or the API’s and not a manually in the UI.
Does anyone know of any way to do this?
tf undo $/ /r
tfpt online /adds /deletes /diff /noprompt
tf checkin /comment:"synchronizing" /noprompt
Get tfpt here if you don't have it already: http://msdn.microsoft.com/en-us/teamsystem/bb980963.aspx

Resources