Git代码管理之——git revert与git reset
我在git使用上已经吃过好几次亏了,为些,还有两次被老大批,但我始终相信git一定是代码管理中很重要的工具,
并且,熟练的使用git能帮助我们Effective Work
这里讲一下git revert和git reset的区别:
git revert 是撤销某次操作,此次操作之前的commit都会被保留
git reset 是撤销某次提交,但是此次之后的修改都会被退回到暂存区
具体一个例子,假设有三个commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
当执行git revert HEAD~1时, commit2被撤销了
git log可以看到:
commit1:add test1.c
commit3:add test3.c
git st 没有任何变化
如果换做执行git reset --soft(默认) HEAD~1后,运行git log
commit2: add test2.c
commit1: add test1.c
运行git st, 则test3.c处于暂存区,准备提交。
如果换做执行git reset --hard HEAD~1后,
显示:HEAD is now at commit2,运行git log
commit2: add test2.c
commit1: add test1.c
运行git st, 没有任何变化
另外:
git revert <commit log string>是撤消此次commit作为新的
view plaincopy to clipboardprint?
01.koffu@ubuntu:~/share/bak/m2/kernel_rk29_M2$ git log
02.commit dff2942d5b1bd0f2889c07ef540a2254cbf4ad38
03.Author: xugangfeng <xugangfeng@skyworth.com>
04.Date: Mon Aug 29 19:35:47 2011 -0700
05.
06. Modify Codec(CS42L52) Output Mix Left&Right for M2
07.
08.commit 74ab03af93c173aa6b634132a647840efcddff24
09.Author: xugangfeng <xugangfeng@skyworth.com>
10.Date: Mon Aug 29 19:34:49 2011 -0700
11.
12. Modify Skyworth Logo for M2
13.
14.commit 226864f6d9bb9d3b3c4d39106b82ddfd2f5c34d9
15.Author: xugangfeng <xugangfeng@skyworth.com>
16.Date: Mon Aug 29 19:33:08 2011 -0700
17.
18. Add TP(ft5406) Upgrade Function
19.
20.commit 0952635641fdbad57fbaebcbadf7901e2ccd80c5
21.Author: xugangfeng <xugangfeng@skyworth.com>
22.Date: Wed Aug 17 04:08:58 2011 -0700
23.
24. Update M2_defconfig
25.
26.commit <span style="color: rgb(255, 0, 0);">d5da440</span>cb31c10a745b3997ca891fa5b32592059
27.Author: xugangfeng <xugangfeng@skyworth.com>
28.Date: Wed Aug 17 04:08:19 2011 -0700
29.
30. Add M2's Keyboard Defined
31.
32. koffu@ubuntu:~/share/bak/m2/kernel_rk29_M2$ git revert <span style="color:#ff00;">d5da440 <span style="color: rgb(0, 0, 0);">//撤消此次commit
33.
34.Finished one revert.
35.
36. GNU nano 2.2.2 File: .git/COMMIT_EDITMSG
37.
38.Revert "add rockchip pitch "CPU display 1G"."
39.for M2 1G Freq
40.
41.This reverts commit 5627ad4dc4e6bac27229445d6687c85cdcd05d89.
42.
43.# Please enter the commit message for your changes. Lines starting
44.# with '#' will be ignored, and an empty message aborts the commit.
45.# On branch 3fa5f9f
46.# Changes to be committed:
47.
48.//作为一个新commit log信息提交
49.
50.</span></span><pre name="code" class="html">
koffu@ubuntu:~/share/bak/m2/kernel_rk29_M2$ git log
commit dff2942d5b1bd0f2889c07ef540a2254cbf4ad38
Author: xugangfeng <xugangfeng@skyworth.com>
Date: Mon Aug 29 19:35:47 2011 -0700
Modify Codec(CS42L52) Output Mix Left&Right for M2
commit 74ab03af93c173aa6b634132a647840efcddff24
Author: xugangfeng <xugangfeng@skyworth.com>
Date: Mon Aug 29 19:34:49 2011 -0700
Modify Skyworth Logo for M2
commit 226864f6d9bb9d3b3c4d39106b82ddfd2f5c34d9
Author: xugangfeng <xugangfeng@skyworth.com>
Date: Mon Aug 29 19:33:08 2011 -0700
Add TP(ft5406) Upgrade Function
commit 0952635641fdbad57fbaebcbadf7901e2ccd80c5
Author: xugangfeng <xugangfeng@skyworth.com>
Date: Wed Aug 17 04:08:58 2011 -0700
Update M2_defconfig
commit <span style="color: rgb(255, 0, 0);">d5da440</span>cb31c10a745b3997ca891fa5b32592059
Author: xugangfeng <xugangfeng@skyworth.com>
Date: Wed Aug 17 04:08:19 2011 -0700
Add M2's Keyboard Defined
koffu@ubuntu:~/share/bak/m2/kernel_rk29_M2$ git revert <span style="color:#ff00;">d5da440 <span style="color: rgb(0, 0, 0);">//撤消此次commit
Finished one revert.
GNU nano 2.2.2 File: .git/COMMIT_EDITMSG
Revert "add rockchip pitch "CPU display 1G"."
for M2 1G Freq
This reverts commit 5627ad4dc4e6bac27229445d6687c85cdcd05d89.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch 3fa5f9f
# Changes to be committed:
//作为一个新commit log信息提交
</span></span><pre name="code" class="html">