How do I rollback to a previous commit to make changes that were missing without losing all the work completed since?

I need to locally rollback to a previous commit in sourcetree because code is missing from a deployment, but I do not want to lose all the work done that has been committed and pushed since that earlier commit.


I find sourcetree's terminology and options confusing and sometimes they don't work as I would expect them to.

How do I do rollback to get previous versions of files to make changes without losing the changes made recently? Thanks!

4 answers

Why do you need to rollback? Just add the changes in a new commit.

You can select any commit and then select any file within that commit, right click, open selected version.

That will open the version of the file at the time of the selected commit. You can copy and paste changes to the current version of the file.

Without knowing the specifics of your project that's the best approach I can suggest.

In other scenarios you can reset a branch to a particular commit or reset just 1 file to how it used to be in a particular commit or cherry pick another commit onto your current branch or Reverse Commit to undo all changes that were introduced in a particular commit.

The solution that you are probably looking for is called "rebasing". It's a method within git where you rewrite a portion of the git history.

However, this is a very bad approach if you've already pushed the commits you want to modify. The reason for this, is that rebasing essentially discards the old commits and creates new ones with new hashes. Any coworkers/team members that have pulled the unedited commits are going to start getting very strange error messages if they try to do any work in that branch, and will have to jump through a bunch of hoops to "repair" their local repositories.

The right solution is to just make a new commit that has the fix you need, and deploy that instead of whatever you are currently trying to deploy.

Don't worry. I think Sourcetree was playing up as when I reset my branch I could make the edit, deploy the DLL and then PULL all commits again. smile

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

502 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot