Git常用命令

博客介绍了项目错误恢复的方法。一是通过传递(force)选项给Git命令来撤销更改;二是利用分支增强抗错性,当分支有误或项目存在bug和缺陷时,可使用git log获取SHAs并检出对应版本。

项目错误恢复

  • 方法一:
$ 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
View Code

 

$ git checkout 03aff34ec4f9690228e057a4252bcca169a868b4

 

转载于:https://www.cnblogs.com/cwhycwhy/p/10825564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值