Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source tree how to discard an un pushed commit and go step back

i am using Sourcetree git client with git lab. I am new to version control. Is there any way to discard my commit and go back. I haven't pushed that commit.

like image 457
Saifullah khan Avatar asked Jun 03 '16 13:06

Saifullah khan


People also ask

How do you remove commit that is not pushed SourceTree?

In the new window, select the commit you want gone, and press the "Delete"-button at the bottom, or right click the commit and click "Delete commit". Click "OK" (or "Cancel" if you want to abort).

How do I revert pushed changes in SourceTree?

When you push a commit, the safest way to revert it (rather than forcing the push with -f) is to use the revert function, so a new commit is created on top of your previous commit. This is possible to do using Sourcetree, right clicking in the commit that you want to revert, and selecting "Reverse commit...".

How do I revert a commit in SourceTree?

Click top right corner "Terminal" option of Sourcetree. When the commit message editor opens up: For just accept and exit, write :q then click enter. If you want to change the commit message, press "i", write your message and then write :wq click enter.

How do I discard a previous commit?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


2 Answers

Just right click on your commit and reverse it.

like image 122
ayaz javed Avatar answered Nov 09 '22 23:11

ayaz javed


I don't know about Sourcetree, but in "normal" git, i.e. command line git, you would simply do a soft reset:

git reset HEAD^

This will remove the commit but will leave the working directory, i.e. your actual files, as they are. You can then commit these changes in a new commit.

like image 33
mattmilten Avatar answered Nov 10 '22 01:11

mattmilten