How to rebase in TFS using TFVC? (like git rebase functionality) - version-control

Using tfs2015 (not git but tfvc)
We have a MAIN branch and I created my development branch from MAIN branch.
__MAIN (branch)
|__MYDEV (my new branch)
After a while, my friends pushed 2 new changesets to MAIN.
__MAIN [change1], [change2]
|__MYDEV [mychange1]
Question: How can I get those 2 changesets onto MYDEV branch as 2 changesets as they are by merging (rebasing) my change on their changes?
If I try merging MAIN onto MYDEV, 2 changesets are coming as pending changes of bunch of files, but I want them as they are as packaged in 2 changesets and put my changes on them.
Finally what I expect,
__MAIN [change1], [change2]
|__MYDEV [change1], [change2], [mychange1-with-merge-fixes]

If you use git-tfs it will give you all the powers of git, highly recommended. Now, visual studio will maybe be a little bit upset when it detects a .git directory, but you can avoid that by setting GIT_DIR and GIT_WORK_TREE environmental variables (see this answer for details).

You can use "Rebase" tool to keep every merged changeset separately in the branch.
To use rebase tool in TFS, follow the steps below if you have Team Explorer installed:
Launch Team Explorer and connect to your project.
Open "Branches".
Checkout the branch (MYDEV) you'd like to rebase.
Right click the branch and select "Rebase Onto..." option.
Select the Onto Branch (MAIN) and then click "Rebase" button. (Resolve the conflict and click "Continue" button if there is any conflict during the rebasing)
Introduction about TFS Rebase: https://msdn.microsoft.com/en-us/Library/vs/alm/Code/git/rebase

Related

Eclipse Git : auto-synchronising 2 branches

I am working on a project with some mates.
Yesterday I cloned the project with the intention to add a functionality.
I have 2 local branches that are develop (the main branch) and pageContent (my feature branch).
The problem I am currently encountering is when I edit something on my feature branch, it automatically edits it on my developp branch too (I did not commit anything).
I checked out on my developp branch to delete the edition and when I checked out on my feature branch, the edition was deleted too ...
The branches seem to be auto-synchronised.
I checked out on my develop branch to delete the edition and when I checked out on my feature branch, the edition was deleted too ...
This is how git works.
In the following diagram you can see the 3 states.
Git has three main states that your files can reside in.
They are all shared between your branches. but when you checkout branch you change the HEAD so you end up with the staging area && working directory shared between your repository even when you checkout branches.
Since you did not commit (i assume that what happened) when you switch branches you see the changes following you to your new branch.
If you don't want the changes to follow you you need to commit (or stash) your work before switching to the branch.
How to checkout different branch with clean working directory and stage area?
If you wish to checkout clean branch without any "leftovers" in your working directory and staging are you can create a new worktree which will result in shared view of your repository (all the content is shared) but with a different working directory and staging area.
From git v2.5
git worktree add <new_path>
Now do whatever you want in any of your branches. It will create 2 separate working folders separated from each other while pointing to the same repository.
Using wortree you don't have to do any clear or reset in order to remove all your staged and untracked content.
Here is demo of how to do it:

How can someone using egit/eclipse pull a remote branch that I created without using command line?

This is probably quite simple, but I am just not familiar with eclipse. I have a dev branch that I have pushed to the server for review using the basic git push origin dev. My co-worker is new to git and would prefer to stay within eclipse to review the code. He has egit installed and I cannot seem to find a way to pull a specific remote branch. I know this is brief but I am more than willing to provide any information for clarification.
To easily review the changes, your co-worker can check out the remote branch as a new local branch and then look at the code and commits.
One possible way is:
Team > Fetch from Upstream to get the newest branches (or a normal pull, which includes a fetch)
Team > Switch to > New Branch...
Select origin/dev (assuming the remote is named origin) as the base branch
Click Finish to check out the new local dev branch
It can also be done via the Git Repositories view by expanding Branches > Remote Tracking and using Create Branch... from the context menu.
Another way is to find the branch in the History view (you may need to toggle the Show All Branches and Tags option, see here) and use Create Branch... there.

git modifying code on multiple branches using the same eclipse workspace

I kind of feel I am missing something here, but here is the question.
I have a branch A. Work is in progress in this branch. A tag T is created which marks a production release version. Now, a fix has to be done on top of the code in this tag. So I created a branch B out of the tag. The branch would contain stable production code.
My eclipse points to checked-out code in branch A.
Now, I want to make changes to code in branch B. How can I make my eclipse realize that there are 2 different branches and the code is different?
Do I have to clone the branch B and point a new eclipse workspace to it?
Cant I use the same workspace and have 2 different versions of the same file - one from branch A and another from Branch B?
Just checkout branch B in your workspace, make your changes, commit, and then you can checkout again branch A and continue to work on branch A. Eclipse will automatically recognize the content of the other branch
However, you should be aware, that you shouldn't have uncommitted changes in your workspace, when you checkout another branch. Either commit your changes or stash, before checkout.
assuming you have eclipse integrated with your git system, you can use select the project you are working on, and then in the context menu, use "Team->Switch To->New Branch...", and choose branch B.
if you don't have it integrated, you can do so with the following 2 steps.
using the git perspective, in the Git Repositories view, find the icon with the + to perform Add an existing local Git Repository to this view .
in the subsequent dialog, choose the location of your repository.
once it's added, go back to your java perspective, and from there, select the project in git (which you currently have in branch A), and from the context menu, select Team->Share Project

tortoise hg creating 'sibling' branches

I'm just starting working with Mercurial and Tortoise HG. I've created two uncoupled changes, one is a bug fix and one is a new experimental feature.
What is the best way to set this up (using bookmarks, tags or branches or something else) so that I can commit both but push only one of the groups of changesets to the remote repository.
And can this be done easily in Tortoise HG or is command line knowledge of mercurial required?
You can do this from both the CLI and from TortoiseHg. Note that using bookmarks, tag, etc.. has no influence on what you can push.
Using TortoiseHg v1.X.X
Identify the outgoing changesets and then right-click on the head of the branch you'd like to push and select push this branch.
Using TortoiseHg v2.X.X
You must first configure the tool to allow pushing new named branches by clicking Options and selecting the following:
Using the Target option in the Synchronize view, select the branch you want to share and perform the push. This will only share the selected branch. Unchecking Target will cause every new changeset to be pushed.

TortoiseHg: Push Branch

I am working on some bugs in our code base and I have created separate branches for each bug. I have rebased one of the branches on top of default. I generally use the mercurial plugin for Eclipse and I would do a push (when I am in the default branch). This pushes my changes on the default branch.
I tried to do the same thing with TortoiseHg. When I press push, the client complains that I am about to create remote heads/create new branches on the server. Is there some way to push only changes on one branch using TortoiseHg?
Thanks for your answers!
Here’s another way to do it:
Open Repository Explorer.
Click Determine and mark outgoing changesets (green up arrow button). All your changesets / branches will be marked with an up arrow.
Right-click on the changeset you want to push. From the menu, select Push to here.
Works the same way as the previous answer, but allows you to select the changeset from the list, without typing or pasting the target changeset id.
The easiest way to do this is via the command-line using hg push -r . from the branch with the change you want to push. See hg nudge for details.
That being said, it is also possible via TortoiseHG:
Open your Repository Explorer
Open Tools->Synchronize
Open "Advanced Options"
Set "Target Revision" to the changeset that you want to push
Select "Push"
This should only push the changeset you specified (along with any parents of that changeset which may be required). If you limit the changesets that are pushed to those on your default branch, there should be no warning about creating additional heads.
More information (well, not that much) can be found in the Section 4.9 of the TortoiseHg documentation.