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

This widget could not be displayed.

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

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

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

721 views 1 3
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