12.5 反转提交

    空标题文档 - 图1


    index 51dbfd2..ceaf01b 100644 —-a/README +++b/README @@-1,3+1,4@@ Hello. Nice to meet you. Bye-Bye. +Wait… diff—git a/src/hello.h b/src/hello.h index 0043c3b..6e482c6 100644 —-a/s r c/hello.h +++b/src/hello.h @@-1+1,2@@ /test/ +/end/

    在不改变这个提交的前提下撤销对其的修改,就需要用到git revert反转提交。


    $git revert HEAD

    运行该命令相当于将HEAD提交反向再提交一次,在提交说明编辑状态下暂停,显示如下(注释行被忽略):


    Revert "modify hello.h" This reverts commit 25846394defe16eab103b92efdaab5e46cc3dc22.

    可以在编辑器中修改提交说明,提交说明编辑完毕保存退出则完成反转提交。查看提交日志可以看到新的提交相当于所撤销提交的反向提交。


    $git log—stat-2 commit 6e6753add1601c4efa7857ab4c5b245e0e161314 Author:Jiang Xin<jiangxin@ossxp.com> Date:Mon Dec 13 15:19:12 2010+0800 Revert "modify hello.h" This reverts commit 25846394defe16eab103b92efdaab5e46cc3dc22. README|1- src/hello.h|1- 2 files changed,0 insertions(+),2 deletions(-) commit 25846394defe16eab103b92efdaab5e46cc3dc22 Author:Jiang Xin<jiangxin@ossxp.com> Date:Sun Dec 12 12:11:00 2010+0800 modify hello.h README|1+ src/hello.h|1+ 2 files changed,2 insertions(+),0 deletions(-)