How can I use SourceTree to roll back my Git repository to an earlier commit?

I am entirely new to Git, SourceTree, and everything about it. I am using SourceTree with Bitbucket but I need some help. As I know absolutely nothing about Git or SourceTree, I would like to learn how to use SourceTree to revert all the files in my Git repository to the state they were in when I made an earlier commit. Basically I want to roll back to an earlier commit so that I can access the files as they were at that point, but I want to be able to keep my existing commits so that I can roll forward as necessary. I also want to be able to make commits of the files based on the files from older commits. How can I do all of this?

3 answers

2 votes
Chris Fuller Atlassian Team Nov 29, 2014

Disclaimer: I'm a command line guy, so I haven't used SourceTree enough to tell you specifics, there.

As I read your question, all you are really wanting to do is view that version of the tree, not undo everyone's changes.  This is simply a "checkout".  Given SourceTree's GUI nature, I would expect this to be something like right-clicking on the commit you are interested in and choosing the checkout from a pop-up menu or something similar.

For reference, the command line version of doing that looks something like this:

cfuller@crf:~/src/atlassian/jira-bugfix [(atlassian_jira_6_3_8)]$ git log --oneline | head -5
68f19fa AUTOCOMMIT bump JIRA version from 6.3.8-SNAPSHOT to 6.3.8
514f45b NONE: Fix webdriver batches PT so it doesnt duplicate the definition of batch 06
7facb80 JDEV-30619: Updating variables for 6.3.8 stable release cut
27029ae Merge pull request #1810 in JIRA/jira from stable-issue/JDEV-30651-upgrade-dvcs-connector-2.1.24 to atlassian_jira_6_3_branch
76d9270 Merge pull request #1799 in JIRA/jira from stable-issue/SW-533-inline-component-bugfix to atlassian_jira_6_3_branch
cfuller@crf:~/src/atlassian/jira-bugfix [(atlassian_jira_6_3_8)]$ git checkout 76d9270
Previous HEAD position was 68f19fa... AUTOCOMMIT bump JIRA version from 6.3.8-SNAPSHOT to 6.3.8
HEAD is now at 76d9270... Merge pull request #1799 in JIRA/jira from stable-issue/SW-533-inline-component-bugfix to atlassian_jira_6_3_branch
cfuller@crf:~/src/atlassian/jira-bugfix [(76d9270...)]$

 

My working directory has now been set up exactly as things were at that commit.  To get back, I just checkout the original position:

cfuller@crf:~/src/atlassian/jira-bugfix [(76d9270...)]$ git checkout HEAD@{1}
Previous HEAD position was 76d9270... Merge pull request #1799 in JIRA/jira from stable-issue/SW-533-inline-component-bugfix to atlassian_jira_6_3_branch
HEAD is now at 68f19fa... AUTOCOMMIT bump JIRA version from 6.3.8-SNAPSHOT to 6.3.8
cfuller@crf:~/src/atlassian/jira-bugfix [(atlassian_jira_6_3_8)]$

Thank you for your help. As I am new to Git, I am using SourceTree for now, but eventually I would like to transition to command line usage.

Hi David,

You should explore more about the following commands

  1. checkout
  2. revert

Documentation and tutorials available at

https://www.atlassian.com/git/tutorials/undoing-changes/git-revert

Thank you, but I am new to Git and want to learn how to use Git with a user interface (SourceTree) before using command line to do everything.

Also, as someone who is new to Git, you should read the Git book. It won't take much time. You should focus on 1.1-1.3 and chapters 2 and 3. The examples there are all command line, but understanding the terminology will make the Sourcetree UI much more intuitive.

Thanks for the suggestion! I'll certainly do it!

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

692 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