Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to delete Commits?

paranoid93 April 17, 2014

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

1 vote
Answer accepted
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2014

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
TAGS
AUG Leaders

Atlassian Community Events