项目错误恢复
- 方法一:
$ echo >> about.html # Appends a newline to about.html
$ echo > about.html # overwrite about.html
with a newline
[website (master)]$ git checkout -f
undo the changes by passing the -f
(force) option to checkout
, which forces Git to check out HEAD. The state of the repository as of the most recent commit (a state known as
HEAD
)
- 方法二:
Another source of robustness against error is using branches.
当在一个分支有误时:
$ git branch -D test-branch
当错误涉及bug和缺陷在当前项目, 可以用git log 获取SHAs, check out 对应的版本:


$ git log commit 8c19674468a67720b9ba61a783e81f97062874bf Author: Michael Hartl <michael@michaelhartl.com> Date: Mon Dec 21 21:27:56 2015 -0800 Add a README commit 69b955490caf12552e83d476820d29475fa35010 Author: Michael Hartl <michael@michaelhartl.com> Date: Mon Dec 21 21:02:20 2015 -0800 Add some HTML structure
$ git checkout 03aff34ec4f9690228e057a4252bcca169a868b4