Reset commit in SourceTree

46,857

Solution 1

You need to run this command in source tree terminal git reset --soft HEAD~1 this command push back your commit in your sourtree. then you take latest pull and then you can commit your code.

Solution 2

Simply go to Log/History in source tree, select the previous commit of the commit which we you want to undo and right click and do 'Reset current branch to this commit' This will discard your committed changes(which were not pushed).

It won't impact anything in master branch

Solution 3

If you have not pushed your code to remote you can revert your change by following below steps shown as in the image.But please BACKUP your Changes first revert changes 1. Go to SourseTree terminal
2. Execute the command git reset HEAD~

Then go to file status and check.


Solution 4

I don't think doing a git reset --soft will affect any commits. It will only affect your branch.

If you want to revert commit 734e3a0 then you can try using git revert:

git revert 734e3a0

This will instruct Git to add a new commit which undoes whatever 734e3a0 was doing originally. Note that this is a good option in the event that this commit is in the middle of a branch, and it is also a good option for a branch whose history has already been made public.

Solution 5

First of all you have to ask yourself what you want to do.

What is reset is for?

I assume you want to undo your changes. Do do so you have several options, which you can read about in details in here:

How to move HEAD back to a previous location? (Detached head)

It will explain in details what to do in each option.


What needs to be done?

You have to set up your HEAD to point to a new (or old) commit.
The above post will show you and will teach you what to do and will show you few options.

Share:
46,857
Roe
Author by

Roe

Updated on July 17, 2022

Comments

  • Roe
    Roe almost 2 years

    I have 2 branches master and bugfix. my current branch is bugfix, where I have committed my changes (not pushed), now I need to reset this commit.

    If I do reset my commit, will it affect other commits in master branch?

    Actually I want to remove this commit.

    git reset --soft 734e3a0
    

    I am using SourceTree.

    • Tim Biegeleisen
      Tim Biegeleisen about 8 years
      git reset --soft does not "affect" commits, rather it moves the HEAD of your branch to point to a different commit. Can you update your question with what is your situation for wanting to do this?
    • Tim Biegeleisen
      Tim Biegeleisen about 8 years
      Take a look at the edited answer below.
    • Rahul Soni
      Rahul Soni over 6 years
  • Chuck
    Chuck about 8 years
    I agree, but I don't have enough reputation.
  • Radu Simionescu
    Radu Simionescu almost 7 years
    the question was pretty clear. A reset is wanted and possible since the commit was not pushed. A revert would result in an additional commit.