Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git, cancel latest commit that is first commit

Tags:

git

I created the first commit of my project, but forgot to ignore node_modules.

I tried this solution to cancel the commit. However, it returns me this (sorry, virtual machine without copy/paste capacity):

enter image description here

As you can see in the screenshot above, it is not capable of doing what I expected. (red lines to isolate commands and help reading)

How can I cancel latest commit considering that it is the very first commit ?

like image 296
Itération 122442 Avatar asked Jun 15 '26 18:06

Itération 122442


1 Answers

You don't need to remove the commit. You can remove the node modules, edit the .gitignore and amend the changes to the last commit (which is also the first in your case):

# changes
git commit --amend
git push -f

If you insist to remove the commit, you can run

git update-ref -d HEAD
git push -f
like image 197
Maroun Avatar answered Jun 18 '26 07:06

Maroun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!