$ git status # 可以看到 SHA1 为 4f4d141 的 commit 上的更改回到了缓存区,如果要继续提交,只需要再次 commit On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: 4.txt
git reset --hard
具有破坏性,是很危险的操作,很容易导致数据丢失
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ git reset --hard HEAD~2 HEAD is now at 390064f 2.txt
$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) 3.txt 4.txt nothing added to commit but untracked files present (use "git add" to track)