Search code examples
gitatlassian-sourcetree

How to remove merge of master into branch (using sourcetree)


I have messed up my git repository a bit. I have worked on several branches at one and made merges which in retroperspective were a really bad decision.

I was working on branches JIRADAPTER-108, JIRADAPTER-109 and JIRADAPTER-104 (see attached picture of the history). JIRADAPTER-108 and JIRADAPTER-109 were bugfixes which i branched from master and merged back to master with only one commit respectively. To use those changes I decided to merge the master into branch JIRADAPTER-104, which turned out to be a bad idea!

At first glance i was not able to merge back everything from branch JIRADPATER-104 into master, as foxtrot merges are not allowed. This was, as I tried to merge from origin/JIRADPATER-104 (last green commit).

I was able to merge the right changes into master by merging from the last commit before merging the master into JIRADAPTER-104 (last pink commit).

Although only cosmetic, i now, try to get rid of those to commits to branch JIRADAPTER-104, where i merged the master into it (all green commits).

I was trying to reset to the last pink commit: without success.

Can anybody help me to get rid of those two green commits, so that origin/JIRADAPTER-104 and JIRADAPTER-104 tags are on the last pink commit?Branches

EDIT Using worktree, be sure to have set the option Enable Force Push under Tool > Options > Git.

Then the workflow is quite similar as Mlad274 suggested (many thanks for that):

  1. Click on the commit which should be last in a branch
  2. From the context menue select Reset current branch to this commit
  3. Push (select Force Push at bottom of the menu`)

Solution

  • Since you know the commit you want, just force the branch to point to it.

    1. git checkout JIRADAPTER-104
    2. git reset --hard <COMMIT-ID>
    3. git push -f