Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

David Berdik November 29, 2014

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
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 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)]$
David Berdik December 2, 2014

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.

1 vote
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.
December 1, 2014

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.

David Berdik December 2, 2014

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

1 vote
Bhushan Nagaraj
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 29, 2014

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

David Berdik December 2, 2014

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events