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

Reset branch to different commit (Git)

MikeL November 15, 2011

How can I reset (hard or soft) my current branch to a different commit?

1 answer

0 votes
Colin Goudie
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 15, 2011

git reset --hard COMMIT_ID

e.g.

git reset --hard 0f347f

With SourceTree you would probably right click on the commit and do a checkout (discard changed) or something

MikeL November 15, 2011

I know how I can do that on command line, but I want to avoid command line at all. BTW, the Reset toolbar button exists, but is disabled.

stevestreeting
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 15, 2011

As Colin says, right-click a commit in the log and select 'Checkout'. You can also use the Checkout toolbar button / menu item and select an item from the list in the dialog.

MikeL November 17, 2011

I've tried, but Checkout just changes what working tree state I will have. It does not move my current branch to the selected commit. Is the Reset feature missing in SourceTree though a toolbar button with this name already exists?

stevestreeting
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 17, 2011

'git reset' has many different modes, SourceTree uses the most common one which is to undo your working copy changes. Checkout effectively does 'git reset' followed by 'git checkout' for missing files.

You're clearly looking for 'git reset --hard' to move your branch pointer elsewhere. SourceTree doesn't support that yet.

stevestreeting
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 17, 2011

I've logged this as a feature request here: https://jira.atlassian.com/browse/SRCTREE-770

MikeL November 17, 2011

Not just reset --hard, but also --soft and --mixed. All those move the branch pointer, but do different things with the index or working tree.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events