Convert changeset(s) to shelveset - tfs

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.

Related

Copy source files to other TFS

We have a TeamCity/Octopus setup that runs great for several projects.
A new client wants access to the source code during development. Is it possible to copy code from our TFS to an other TFS using TeamCity? It does not need to be real-time. Daily copies are OK.
Not sure if we should use TeamCity for this or if there are possibilities within TFS itself.
You could setup a daily build schedule and use the TFS command line utilities to transfer the files to another server. You'll probably get all kinds of sync issues along the way, unless you always take your own solution as the current situation.
Look at tf.exe, especially the workspace, workfold commands and add, delete, and optionally destroy. Complete the job with a tf checkin.
Process as follows:
Create a workspace on your source TFS server (or use the built-in workspace features in team city): tf workspace /new
Map the folders you want to share: tf workfold /map
Get the files to the machine that's doing the transfer: tf get /recursive
Create a workspace on your target TFS server: tf workspace /new
Map the folders you want to share to tf workfold /map to a new folder that's not mapped to the source TFS server.
WS2 delete the files in the target folder: tf delete * /recursive
WS2 Check in to make sure you won't get any conflict remotely: tf checkin /recursive
WS1 -> WS2 Copy the files from the first workspace to the second: xcopy
WS2 Add all files: tf add * /recursive
WS2 Checkin all files tf checkin * /recursive
WS2 & WS2 Delete the workspace: tf workspace /delete
(Optional) Delete the files in the folders of the deleted workspaces on disk.
PS: if you move to git, this all becomes a lot easier, since the distributed nature of git is kind of meant for scenarios like these.

How to track the branched history through tf command?

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

How to remove Excluded Changes from 'tf diff' output?

To create a unified diff of pending changes, you can use the tf diff command like so:
tf diff /recursive /format:unified C:\Development\MyProjectDir > pendingChanges.diff
However, this will output a diff containing changes to files both in the "Included Changes" and the "Excluded Changes" sections of the Pending Changes window in Visual Studio. Is there any way to output a diff just with changes to files in the "Included Changes" section?
If you put the changes you want in a shelveset you can compare the shelveset to the changeset the shelveset is based on.
The updated command would then be something like (assuming you run it from the root of your workspace folder)
tf diff /recursive /format:unified /shelveset:MyPendingChanges . > pendingChanges.diff
Refer to the docs for more information

Create TFS 2010 branch from checked out items?

I've edited some files in Branch1 and found out I would like to check the pending changes in to a new branch, Branch2. Is this possible?
I know I can create the branch as normally and then copy all the changed files to Branch2 by hand but that can be cumbersome.
You can shelve your changes and the unshelve them into another branch: Can I unshelve to a different branch in tfs 2008?

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