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.
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).
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...".
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.
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.
Just right click on your commit and reverse it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With