Anas Platyrhynchos Anas Platyrhynchos - 1 year ago 64
Git Question

Extracting branch into another under TortoiseGit

Working under TortoiseGit (on Windows 7), imagine having a MASTER branch from which a SPECIFIC branch has been built.

The SPECIFIC contains some parameter changes and some general code changes.

My Question

How do I create a new branch (starting from the MASTER) which keeps the code changes only?

(Of course, I will sort out what exactly is a code change and will be kept. )

What I've tried

So, I created the NEW branch from MASTER, and tried to rebase SPECIFIC onto NEW. All that allows me to do, is do a fast forward merge which is not very interesting.

I sought inspiration from rewrite Git history but I don't see how to get the equivalent to
git rebase -i
in the TortoiseGit interface. I also looked in the TortoiseGit manual which correctly tells me that rebase is quite complex.

Conceptually, what I really want to do is to
SPECIFIC and NEW, and manually sort out the differences.

Even better, NEW could end up being identical SPECIFIC but consisting of exactly two commits: the code changes and the parameter changes.


Answer Source

You have lots of question, I try to answer those, hopefully I don't miss anything important.

The most important dialog is the log dialog for you. Here you can select two commits (e.g., the lastest one of your master branch and the latest of your other branch) and then select "Compare revisions". Then you get a dialog which shows all changes files which you can then diff one by one. You can also select "Show changes as unified diff" in order to get a unified diff file (you can save this file and then apply it again when you need those changes, e.g. using TortoiseGitMerge; right click-move the created .patch file on the working tree folder and select "Review/Apply single patch"). Also, you can select just one commit and see the changes to the previous one OR also compare it to the current working tree (i.e., you can compare each file and apply the changes you want to keep/make).

Rebasing (rebase -i) also works from the log dialog - however it changes the history and puts the commits of one branch onto another branch. First switch to the branch you want to rebase, then right click on the commit/branch you want to rebase your changes onto and select "Rebase". Then a rebase -i equivalent dialog is shown where you can re-order, de-select, edit and squash commits.

Another approach could be that you switch to your master, then select all commits whose changes you want to apply and select "Cherry pick commits" in log dialog context menu. This way you don't alter your "parameters" branch and you can apply those changes to your current branch - if you want to combine several commits into one, choose "squash".