Make any empty repo
$ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /Users/gregg/temp/delme-git/.git/
make one file
$ echo foo > file1
Show the status before commiting
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1
nothing added to commit but untracked files present (use "git add" to track)
commit the one file
$ git add file1
$ git commit -m "initial commit"
[master (root-commit) bf69878] initial commit
1 file changed, 1 insertion(+)
create mode 100644 file1
Make a second file
$ cp file1 file2
Show the status before committing
$ git status On branch master Untracked files: (use "git add ..." to include in what will be committed)
file2
nothing added to commit but untracked files present (use "git add" to track)
Commit the 2nd file
$ git add file2
$ git commit -m "2nd commit"
[master a0d6a5f] 2nd commit
1 file changed, 1 insertion(+)
create mode 100644 file2
Show that reset takes as back to the previous state
$ git reset HEAD~1
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file2
nothing added to commit but untracked files present (use "git add" to track)
The state above EXACTLY matches the state before we committed
Try to go back one more state
$ git reset HEAD~1
fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Doesn't work as original OP pointed out.
Use accepted solution
$ git update-ref -d HEAD
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1
Untracked files:
(use "git add <file>..." to include in what will be committed)
file2
Notice THIS STATUS DOES NOT MATCH THE STATUS BEFORE THE FIRST COMMIT.
The accepted answer is wrong