Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Git removing the last N commits?

According to this question we should be able to remove the last N commits like this (Example uses 2 commits):

git reset --hard HEAD~2
or
git reset --hard HEAD^^

However when I try this it produces this error (This is a complete rundown):

 % touch f && git add . && git commit -m "M"
[master (root-commit) fc2ff7f] M
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 f
 % touch f2 && git add . && git commit -m "M"
[master 6017bff] M
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 f2
 % git log
commit 6017bff2f76fe15e6e7c99e3d386ef12db4d3ffb (HEAD -> master)
Author: Ole Ersoy <ole.ersoy@gmail.com>
Date: Wed Dec 6 14:17:11 2023 -0500

    M

commit fc2ff7fc92eebb6c7384d9887faf9c608c891ae0
Author: Ole Ersoy <ole.ersoy@gmail.com>
Date: Wed Dec 6 14:17:06 2023 -0500

    M

 % git reset --hard HEAD^^
fatal: ambiguous argument 'HEAD^^': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Thoughts?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You cannot reset to an empty git repository. You must have at least 3 commits in your repository in order to remove two commits.

Add one more commit and then try either command again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading