Search code examples
gitatlassian-sourcetree

Deleting commits with SourceTree


I'm new to Git, and I only understand how to use it with SourceTree (a little bit)

My branch-graph is this:

 o   Commit E is origin/test and (local) master
 |
 | o Commit D is origin/master
 | |
 | o Commit C
 | |
 | o Commit B
 |/
 o   Commit A
 |

Now, I want to:

  • delete the Commits D, C and B
  • move the origin/master to Commit E
  • delete the origin/test branch tag

But I don't find the right buttons and commands in SourceTree.


Solution

  • What you want to do is push your (local) master branch to origin with --force to signify that you want to rewrite history. i.e : you know your changes will cause the origin/master branch to loose history (the 3 commits B, C, D) and you don't care.

    I don't know sourcetree well enough to tell you if such an operation is possible, the GUI is evolving all the time and they add new functionnality to support more operation every month, but you could always open the git console from sourcetree (at least until 1.3 there was an icon to do that) and enter :

    git push --force origin master

    This will push your (local) master branch to its tracking branch (which should be origin/master).

    N.B: I don't know how you configured your SourceTree, but if you rely on https to communicate with the server you might have to enter a login/password.

    EDIT 1:

    If you also want to remove the origin/test you can do this by right-cliking the branch (under remotes)in sourceTree and selecting delete :

    https://answers.atlassian.com/questions/65053/how-do-you-remove-branches-from-source-tree

    EDIT 2:

    Apparently a GUI option for push --force was/will be added to version 1.7

    As a more general answer : Stackoverflow isn't google. SourceTree is a free commercial software backed by Atlassian. They have support for you. They have an ok'ish manual and a user base sufficient not to be the first newbe to wonder how to do X. Just google it.