Search code examples
gitatlassian-sourcetree

Effectively revert to a previous commit in Sourcetree


I am trying to actually revert to a previous commit, effectively cancelling every change that has been made after it, and making this previous commit the current one, at the top of the list.

But when I use the function "Reset current branch to this commit", I am then unable to do anything until I pull back all of the commits I am trying to cancel.

I feel like a lot of people have been asking that exact same question in the comments of other posts, but they never receive a clear answer. What is the procedure for doing this?


Solution

  • Since you don't want to cancel/delete the following commits, I wouldn't use "Reset current branch to this commit" at all in that case.

    I would open the Terminal and enter git checkout c17c46e ./ (replace c17c46e with the actual commit hash).
    The files under ./ (i.e. all the tracked files) will be changed to their older states.
    The ./ is necessary so that it doesn't simply switch to an earlier position and create a detached head.

    Also, the commit hash doesn't have to be typed manually, as you can right click a commit and click 'Copy SHA to Clipboard'.

    After running that command, you can commit the results and push it to the remote.