Search code examples
gitatlassian-sourcetreesourcetree

How to rebase specified commit to different branch using SourceTree?


I have the following situation:

SourceTree Git log output

How can I rebase last commit from staging (removed ProxyFinder...) onto warning-fixes using SourceTree?

One way would be to merge staging into warning-fixes and then reset staging to previous commit, but that sounds like nasty workaround.


Solution

  • The best way to do it is as mentioned in @ElpieKay's comment, and at the end of your question: merge staging into warning-fixes and then reset staging to previous commit.

    To do it from the command line, do:

    git checkout warning-fixes
    git merge staging
    git checkout staging
    git reset --hard HEAD^
    

    In SourceTree:

    1. Double-click warning-fixes to check it out.
    2. Right-click on staging.
    3. Click Merge staging into current branch.
    4. Double-click staging to check it out.
    5. Right-click the previous commit, where origin/staging currently is.
    6. Click Reset current branch to this commit.

    The reason you don't want to use rebase is that it doesn't just move the commits, but it also moves the branch pointer. In this case, attempting to rebase staging onto warning-fixes would have no effect, since the commit at the tip of staging already has the same parent as the tip of warning-fixes.

    The only real alternative is to use cherry-pick, but this will (by default) create a duplicate commit with a new committer date. (And it becomes a pain if you have more than one commit to move.)