Completely override a branch in TFS 2008 - tfs

Is there a way to override a branch in TFS 2008 with the content of its parent?
I've tried a merge (but no way to specify a complete refresh in the UI)
but i am unsure because i would like to completely refresh the entire branch.
any thoughts on that?

If you want to synchronise the branches so that the child branch is identical to the parent, I'd just take a new branch from the parent. This is the easiest way to make sure that they are completely the same. You can then delete \ archive the old child branch.
If you merge from the Parent to Child TFS will check all the files in the branch and the following rules apply
If a file has been modified in the parent, but not in the child (since the child branch was created) then the file from the parent will overwrite the file in the child.
If a file in the child has been modified, but not in the parent (Since the child branch was created) then the file in the child will not be overwritten
If a file has been modified in both the child and the parent (since the child branch was created) then TFS will bring up the conflict resolution tab and you will be given the option to keep either version of the file, or to merge the files creating a 3rd version that contains a combination of the changes.
In the conflict resolution tab you can select all files and choose to keep the version from the parent. However any files modified only in the child will not be overwritten (see point 2)
You could also use the command line option
tf merge $/Project/Parent $/Project/Child /force /recursive
This will tell TFS to attempt to merge files that it already thinks have been merged to the file. I still don't think it will merge files that haven't changed since the child was created though.

Related

What happens in TFS when merging 2 different branches where same file is modified in 2 branches.

There is Main branch
I created a new branch from Main called 'PBI'
There is a file called 'publisher' which is modified in Main and it is also modified in 'PBI'
I want to make sure all the changes in Main are reflected in PBI, so I decided to merge main onto PBI so that PBI is upto date with Main.
When I did the merge, in pending changes it showed publisher[merge]
So what happens now when I checkin the pending change which is publisher[merge]
My changes for 'publisher' in PBI remain? ; If this happens it is a disaster, whats the point of merge
The new changes in Main overwrite the content in PBI branch for 'publisher'; If this happens, it is a disaster too
A conflict arises and I need to choose which one remains. This makes sense
Just as Daniel mentioned, you need to check the documents first:
Resolve Team Foundation Version Control conflicts
Then try to set AutoMerge.
By default, VS will popup the Resolve conflicts dialog when have conflicts during the mergering. You can select the merger action to merger the conflicts manually.
You can also have a try for the Auto Merge extension:
Auto Merge for Visual Studio 2017
Auto Merge for Visual Studio 2015
Depends. Git can auto-merge most of the time, meaning you'll keep the changes for both. When Git can't figure out how to auto-merge your changes (For example, if both branches modified the same line when compared), then a merge conflict will arise, and you'll have to go in there manually and resolve it

Remove changes from branch in TFS

I have a common brach "root" and several child branches. A project with a huge amount of changesets is merged back to the root brach, but a several files have been excluded since the were not nescessary. Those were no seperated changesets.
Now I want to start a new project on that branch, but when I attempt to merge this new project back to the root branch, former excluded files occur again.
So, in between projects for the child branch, it is possible to erase all pending changes compared to root branch?
If these files do not need to be tracked by Version Control, you can create a tfignore file to exclude them.
If these files need to be tracked by Version Control in the child branch but does not need to be merged into root branch, you can use tf merge command with "/discard" specified.
/discard: Does not perform the merge operation, but updates the merge
history to track that the merge occurred. This discards a changeset
from being used for a particular merge.

How to get the latest commits from Parent to Child after Merging in TFS

In TFS, I have made a branch from a parent repository some days back and started working on the child as base. During these period, another team made some significant changes in the parent branch and committed yesterday. I have to find a way to get all the change sets from the parent in my branch with out losing my changes. If somebody have any idea, please share
You can simply merge from parent to branch. If there is conflicts, you can compare the files and resolve the conflicts manually. See https://msdn.microsoft.com/en-us/library/ee341461(v=expression.40).aspx

Find TFS items in other branches

Here is a slightly different take on this question (Find the tfs path of merged branch), different enough to deserve its own question.
In the above link, the authors describe how you can programmatically traverse the folder hierarchy using TFS API to determine the parent branch object from a folder or item within a branch, and then you can get the branch information for that branch.
However, a different question is: how do you use TFS API obtain a path to a different branch of the original folder or item, taking into account that the item may have been renamed or moved in the other branch?
For instance: if I have an object $/MyProject/Main/Foo/bar.txt, I can easily figure out that the parent branch is $/MyProject/Main using the method described. However, let's I also have the following versions of this file out there that were created by branching the original files:
$/MyProject/Dev/Foo/bar.txt
$/MyProject/Experiment/Foo/bar.renamed
$/MyOtherProject/Main/openbar.woohoo
How can I determine the list of references to the specific files or folders in a branch? Clearly there is a way to do this because Visual Studio's merge dialog automatically populates the list of available targets with all references to the source file or folder, even if the source is not a branch.
If TFS has been used to move files or rename them, as opposed to using the file system and then checking in 'new' files to TFS then you can use the history window to review the full history of a file, this will show you it's branch history and also any moves / renames that have occurred, this is because tfs uses an identifier for the file rather than its name.

Why are all files marked with 'merge' in TFS?

I am merging my development branch into the main branch. There is only a subset of files that I have changed in my development branch, all other files should remain unchanged. Logically, I only want to merge files which I've changed. I would not check in a file which I did not change.
But when I do the merge operation in TFS, it marks every single file in the tree with change type 'merge'. It looks like I must checkin every single file in the whole source code tree! I really do not want to do this becasue then it becomes impossible to look at the changeset and see what files I acctually changed as part of my project.
At first, I thought I could use the tfpt.exe Undo Unchanged command to undo all the 'merge' changes, but this won't undo those changes.
Anyone have any ideas on this? thanks.
This also happens with a baseless merge. A baseless merge occurs when TFS doesn't have an existing merge relationship between the branches you're merging. As a result, it considers every file 'new' in both branches, so it 'merges' every file.
To create a merge relationship, so that future merges only list the files that you've actually changed, you need to do a baseless merge of all changes up to a specified version so that TFS knows what the common baseline should be. You should do this after merging these changes - it's too late to correct the baseline for this branch now.
If you don't actually want to take any changes from the other branch, but just tell TFS that these are logically at the same version, you can do a merge 'giving credit' for the changesets: tf merge /discard.
There are a number of possible reasons. This is not a complete list:
You performed a namespace operation (delete, undelete, rename) on a parent folder of the
files marked "merge"
You performed a namespace operation (delete, undelete, rename) that had already been performed in the target branch
You performed a sequence of namespace operations that collapsed into a no-op (eg delete + undelete, or rename a -> b -> a)
There are unresolved conflicts
You performing a discard
Note: all of these apply equally to 2005 & 2008.
In Visual Studio 2008 and TFS 2008, this does not occur. Only files that have changed will be marked as merge. If you do a compare of a file between the branch and the trunk are there any changes? Changes such as encoding will still make TFS merge this file back.

Resources