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?
Related
I have a TFS repository on Azure. I am using Visual Studio 2019. I have a TFS branch under a Development folder. I want to copy that branch and make changes to the branch copy, thereby preserving the original branch. How do I do this?
From the command line:
tf vc branch $/project/path/sourcebranch $/project/path/targetbranch /recursive
From the UI, right-click the sourcebranch and pick Branch from the UI, enter the target path and create the branch.
This will create a new folder in your TFVC repository with a copy of the sourcebranch. It will be parented to the sourcebranch as well, meaning any merges will go to the sourcebranch by default.
In some cases you may want to create the branch from a shared parent instead and cherry pick the changes from the current source. That will allow you to merge changes upstream without having to go through the current source.
I checked out some files from the main branch of our code set in TFS. Later, a separate branch was created. I would like to check in my code to the new branch, even though I originally checked it out of the original one. Is this possible?
EDIT: I know I can check in to the main branch and do a merge, but I'd like to avoid that if possible.
Well, it's based on which version control you are using.
If you are using GIT, it's simple. After you created the new branch in the UI, you just need to do a 'check out' of the new branch. Any uncommitted changes will be automatically point to the new branch. You can then commit them there.
If you are using TFVC, you need to shelve your changes on the original branch and unshelve them on the other branch. This functionality is provided using tfpt unshelve /migrate command. More detail steps please refer the question: TFS: submit changes done locally in one branch to another branch
It's also a sample which shows the difference between GIT and TFVC.
Install TFS 2015 Power Tools
Create a shelveset of your changes
Open the Developer Command Prompt
Use the tfpt unshelve /migrate command as such
tfpt unshelve /migrate /source:$/Project/Branch1 /target:$/Project/Branch2
I couldn't do with the answers using Power Tools, so I checked in on the source branch, merged to target, and rolled back from source branch.
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.
I'm trying to use tfpt to migrate a shelveset from a source branch into a target branch, but it doesn't appear to do anything...not that I'd expect much more...but any chance anyone knows what's wrong? I'm following the instructions correctly I think...
I've got:
tfpt unshelve "DbMigrations" /migrate /source:$/TeamProject/Main /target:$/TeamProject/Releases/7.20
What happens after you run the command? You need to have a few things set up before migrating:
A workspace that encompasses both the source and target branches.
You need to run the command in a folder within the source.
Once you run the command you should be asked to merge the changes from the original shelfset into the destination branch and resolve any conflicts, which finally pends a changeset on your client. Nothing is touched on the server until you check that changeset into TFS itself.
I experienced the same problem and I could not get it to work by specifying the shelveset name. However, I discovered that if you remove the name of the shelveset altogether, TFS will pop up a window with a selection list of available shelvesets to choose from. Select the desired shelveset and perform all other merge operations as per normal.
Example: c:[mapped workspace target path] > tfpt unshelve /migrate /source:"$/Sourcepath" /target:"$/targetpath"
You need to use the branch paths on the TFS server, not your local machine. To find the paths, go to source control explorer in visual studio, right click the branch, advanced > properties, and you want the branch name, not the local path. If the path has spaces, wrap it in double quotes.
i have a branch in TFS from my main team project. The changes that have been done on the branch, I want those files to be updated in my main Team project. How do i do that?
From a Visual Studio 2008 command line, you can use the tf merge command. From the Source Control explorer, you can use the Merge Wizard.