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

0 votes
Accepted answer

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
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,129 views 4 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