Best Practice for Reverting...

Hello, I am totally new to this git and repositories thing but I can see the benifits right away.

What is the best way to completely revert to a previous commit? Let's say I want to go back three commits ago and start over from that point. I'm using SourceTree.

1 answer

1 accepted

If you want to trash the last 3 commits, select the commit you want to keep and invoke reset with the hard-option.

Thanks Mike. So in SourceTree is that right click on the commit I want and then choose "Reset master to this commit"? Does that change my local and remote repositories at the same time or is there a step after that for syncing?

If you've already pushed these commits to a remote then you probably shouldn't be doing this, because the commits could already have been seen by someone else, which will then cause them problems if they're effectively orphaned and no longer part of the branch going forward.

If you know for sure that no-one except you has seen these commits then you can push your branch to the remote to bring it back into sync with your own local repo. What the reset is doing is moving the branch pointer backwards, orphaning the commits you made before, and which will get garbage collected eventually if nothing continued to point to them.

Thanks Steve. I'm the only developer on my current project so it's safe to do this but I'll remember in the future not to do it if I'm working with others.

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...

572 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