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

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

whitecobalt-simon November 4, 2016

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

0 votes
whitecobalt-simon November 7, 2016

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

0 votes
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.
November 5, 2016

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.

0 votes
thinsoldier
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.
November 4, 2016

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.

0 votes
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.
November 4, 2016

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events