我们难免会因为种种原因执行一些错误的commit / push,git提供了revert命令帮助程序员修复这样的错误。

举个例子,下图是git commit 的历史记录

git revert 命令会通过一个新的commit 来使仓库倒退一个commit,在上例中,如果程序员想要revert 最新的那次commit (Updated to Rails 2.3.2 and edge hoptoad_notifier)

$ git revert HEAD
Finished one revert.
[master]: created 1e689e2:
"Revert "Updated to Rails 2.3.2 and edge hoptoad_notifier""

git 会自动生成一个 Revert “Updated to Rails 2.3.2 and edge hoptoad_notifier” 为注释的新 commit,这时的历史记录如下

当然,如果revert不顺利的话,程序员需要手动解决conflict的问题。

通常情况下,上面这条revert命令会让程序员修改注释,这时候程序员应该标注revert的原因,假设程序员就想使用默认的注释,可以在命令中加上-n或者$ git revert HEAD~1
fatal: Commit 137ea95 is a merge but no -m option was given.
对于revert merge的情况,程序员需要指出revert 这个merge commit中的哪一个。通过--mainline参数,以及配合一个整数参数,git就知道到底要revert哪一个merge。我们先来看一下要revert的这个merge
commit:

$ git log HEAD~1 -1
commit 137ea95c911633d3e908f6906e3adf6372cfb0ad
Merge: 5f576a9... 62db4af...
Author: Nick Quaranto <nick@quaran.to>
Date: Mon Mar 16 16:22:37 2009 -0400 Merging in rails-2.3 branch

如果使用-m 2会revert第二个commit,也就是62db4af。

$ git revert HEAD~1 --no-edit --mainline 2
Finished one revert.
[master]: created 526b346: "Revert "Merging in rails-2.3 branch"" $ git log -1
commit d64d3983845dfa18a5d935c7ac5a4855c125e474
Author: Nick Quaranto <nick@quaran.to>
Date: Mon Mar 16 19:24:45 2009 -0400 Revert "Merging in rails-2.3 branch" This reverts commit 137ea95c911633d3e908f6906e3adf6372cfb0ad, reversing
changes made to 62db4af8c77852d2cc9c19efc6dfb97e0d0067f5.

自动生成的comment也会标示revert的是merge里的哪一个commit。

最新文章

  1. java 多线程(ReadWriteLock)
  2. oracle round 函数,replace()函数
  3. Io 异常: The Network Adapter could not establish the connection 解决方法
  4. 翻译:在Ubuntu 14.04上安装FTP服务器的方法
  5. 在express中使用Mongoose连接MongoDB
  6. Checbox的操作含已选、未选及判断代码
  7. 设计模式之装饰(Decorator)模式 代码详解
  8. Python之路,Day25-----暂无正在更新中
  9. 强联通块tarjan算法
  10. Eclipse实现图形化界面插件-vs4e
  11. asp.net 在新的页面打开的问题。
  12. Tutorial on GoogleNet based image classification --- focus on Inception module and save/load models
  13. dubbo AdaptiveExtension
  14. jqgrid 滚动分页
  15. Scrum Meeting Beta - 6
  16. 017.1 stringBuffer
  17. python面向对象之类成员修饰符
  18. C++中Vector求最大值最小值
  19. 剑指Offer——数组中重复的数字
  20. oracle入门(5)——java连接oracle数据库

热门文章

  1. 第109天:Ajax请求GET和POST的区别
  2. http2.0可行性研究
  3. 在C++程序中开启和禁用Windows设备的无线网卡的方法
  4. bzoj3306: 树(dfs序+倍增+线段树)
  5. Codeforces 717.F Heroes of Making Magic III
  6. python安装包下载
  7. ubuntu 安装微信开发者工具
  8. 前端PHP入门-015-递归函数-飘过
  9. [DeeplearningAI笔记]序列模型3.2有条件的语言模型与贪心搜索的不可行性
  10. [DeeplearningAI笔记]序列模型1.10-1.12LSTM/BRNN/DeepRNN