How to delete Commits?

I'm new to SourceTree and some Merging kinda fucked up some datas, which completely ruined everything.

Is there a possibility to delete those 2 marked commits and set everything back on the lowest one shown in the screenshot?

1 answer

1 accepted

Yes it is possible, but since those commits were pushed to a remote, it is going to cause a few headaches.

The first step is to get your local repository in sync with origin. I would do a soft reset to commit #1 (the bottom one), then "Stash" whatever is in your working copy (should be the changes you had committed to commit #4). Once you have a clean working copy, pull from origin. This should get you up-to-date with origin.

Secondly, right-click on commit #3 and select "Reverse Commit", then do the same thing for commit #2. This should remove the changes from your selected branch (paranoid-dev).

Thirdly, merge paranoid-dev to master.

Finally, push both branches to remote.

If you want to recover the changes you had originally made in commit #4, Apply the stash you created at the beginning of the process.

If your changes had NOT been pushed to any remotes (or pulled by anyone using you as a remote), you could acheive what you wanted with just the reset from the first step. However, it is dangerous to modify history that has been pulled or pushed to other machines, because other developers suddenly find that their repositories are unexplicably out-of-sync with their remote, and in trying to fix the issue, may restore the data that you tried to remove.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

567 views 1 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you