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
Related
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.
I'm trying to get latest on Visual Studio 2017/Angular project on a another machine and hence getting latest all files. It is taking a long time to 'Overwrite local file or folder' individually. Isn't there a way to Overwrite All local files or folders with single click?
In Visual Studio, from the Source Control Explorer, open the folder you want to overwrite. Use Advanced..., Get Specific Version...
And check the option "Overwrite writable files..."
Optionally check "Overwrite all files", but that should not be required and can take up more time.
You can also do this from the commandline:
tf vc get $/project/path /recursive /overwrite /version:T
And optionally to overwrite all files even if your system thinks they are unchanged:
tf vc get $/project/path /recursive /overwrite /force /version:T
Alternatively, you can use undo pending changes to revert to the last checked-in version, or scorch to clear files that aren't even checked in:
tf vc undo /recursive $/Project/path
and
tf vc scorch /recursive $/project/path
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.
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
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.