1.撤消修改
1)revert:反转提交,它就是把你的一个提交先撤消掉,但是,它跟reset不同的是,你的这次这小会留下记录,这样在你下次需要的时候,可以通过这个节点把撤消的提交恢复
[email protected]7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git pull Already up-to-date. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ vim 1.txt [email protected]zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git add . [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git commit -m "test 1" [work 4f3ab02] test 1 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 1.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ vim 2.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git add . [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git commit -m "test 2" [work c7bc7ce] test 2 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 2.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log -2 commit c7bc7ced616685852b0b225042f34c038979ade4 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:31 2015 +0000 test 2 Change-Id: I68bbc606ae343b33f53747745db9f2a5ccf1bc82 commit 4f3ab0254090a54a2307b14d620f83a744d879b0 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:04 2015 +0000 test 1 Change-Id: I233ee74674f6e3f054c5abe0622e85efcc83b563 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert 4f3ab0254090a54a2307b14d620f83a744d879b0 Finished one revert. [work ab43af6] Revert "test 1" 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 1.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log -3 commit ab43af6847f07d08a6c14cb211ce4007782202f5 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:50 2015 +0000 Revert "test 1" This reverts commit 4f3ab0254090a54a2307b14d620f83a744d879b0. commit c7bc7ced616685852b0b225042f34c038979ade4 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:31 2015 +0000 test 2 Change-Id: I68bbc606ae343b33f53747745db9f2a5ccf1bc82 commit 4f3ab0254090a54a2307b14d620f83a744d879b0 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:04 2015 +0000 test 1 Change-Id: I233ee74674f6e3f054c5abe0622e85efcc83b563 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 2.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ vim 3.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git add . [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git commit -m "test 3" [work f4c241d] test 3 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 3.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log -5 commit f4c241ddb521ad85605687734addaac3887c4a4e Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:15:54 2015 +0000 test 3 Change-Id: I0bfde2e50381d2dc1b2717c0d2d839278f1c5fc6 commit ab43af6847f07d08a6c14cb211ce4007782202f5 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:50 2015 +0000 Revert "test 1" This reverts commit 4f3ab0254090a54a2307b14d620f83a744d879b0. commit c7bc7ced616685852b0b225042f34c038979ade4 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:31 2015 +0000 test 2 Change-Id: I68bbc606ae343b33f53747745db9f2a5ccf1bc82 commit 4f3ab0254090a54a2307b14d620f83a744d879b0 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:14:04 2015 +0000 test 1 Change-Id: I233ee74674f6e3f054c5abe0622e85efcc83b563 commit 7cbfacb7c742ef3afbcb50e56820def5d5d2af6f Author: wangjianhua <[email protected]> Date: Tue Feb 10 18:36:49 2015 +0800 modify hd action mode image of Mms Change-Id: I1856c0554d1a8824c45e547df194b4f9865f2473 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 2.txt 3.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert ab43af6847f07d08a6c14cb211ce4007782202f5 Finished one revert. [work 153148e] Revert "Revert "test 1"" 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 1.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 1.txt 2.txt 3.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$
如果你想把多次的提交转化为一次反转,可以添加参数-n
[email protected]7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert -n c7bc7ced616685852b0b225042f34c038979ade4 Finished one revert. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git st # On branch work # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: 2.txt # [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert -n f4c241ddb521ad85605687734addaac3887c4a4e Finished one revert. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git st # On branch work # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: 2.txt # deleted: 3.txt # [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git commit -m "revert test1 and test2" [work 69b0c2e] revert test1 and test2 2 files changed, 0 insertions(+), 2 deletions(-) delete mode 100644 2.txt delete mode 100644 3.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log -1 commit 69b0c2e45258fcf33203f25444d562a9470092d7 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:19:43 2015 +0000 revert test1 and test2 Change-Id: I6563031fe059a2c5bdf3e6bfa5278849ee0e9964 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 1.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert 69b0c2e45258fcf33203f25444d562a9470092d7 Finished one revert. [work bbe5a74] Revert "revert test1 and test2" 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 2.txt create mode 100644 3.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 1.txt 2.txt 3.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ vim 2.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$
对于一次记录只能进行一次revert,多次连续执行是没有意义的,因为revert一次以后,这次提交的内容已经不存了
[email protected]7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ vim 4.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git add . [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git commit -m "test4" [work 2bc646d] test4 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 4.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log -1 commit 2bc646d2f078f3c03ab5352a13a057fccc83621d Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:21:50 2015 +0000 test4 Change-Id: Ia7dff511d77e566a3920aa4fe29331afd80ed215 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert 2bc646d2f078f3c03ab5352a13a057fccc83621d Finished one revert. [work 85ceb81] Revert "test4" 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 4.txt [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ ls 1.txt 2.txt 3.txt AndroidManifest.xml Android.mk apptests CleanSpec.mk ext MODULE_LICENSE_APACHE2 NOTICE proguard.flags res src [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git revert 2bc646d2f078f3c03ab5352a13a057fccc83621d Finished one revert. # On branch work nothing to commit (working directory clean)
2)历史记录重排序
[email protected]7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -5 c8edf2bebf0bea0906a09d277ad0f1007a791e36 test5 35a249e2cc2acf11a078e28381aee80f602aa64a Revert "test4" 2bc646d2f078f3c03ab5352a13a057fccc83621d test4 bbe5a74e8e0fa135577b1e5dd9554d9e49c90caf Revert "revert test1 and test2" 69b0c2e45258fcf33203f25444d562a9470092d7 revert test1 and test2 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git rebase -i 69b0c2e45258fcf33203f25444d562a9470092d7 Successfully rebased and updated refs/heads/work. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -5 a3dfb66a35509f72ed9606a3614ed0b660c082d0 Revert "revert test1 and test2" 3b850bebefe0b6005845d534875e2d198a879af9 test5 47e439085f53260c1e0d88a6c17370d0a8437aa6 Revert "test4" bcf6a96ef4dba4ee819ce357864911aa60458ae7 test4 69b0c2e45258fcf33203f25444d562a9470092d7 revert test1 and test2 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$
执行了git rebase -i 69b0c2e45258fcf33203f25444d562a9470092d7 命令以后,你会发现如下界面
1 pick bcf6a96 test4 2 pick 47e4390 Revert "test4" 3 pick 3b850be test5 4 pick a3dfb66 Revert "revert test1 and test2" 5 6 # Rebase 69b0c2e..a3dfb66 onto 69b0c2e 7 # 8 # Commands: 9 # p, pick = use commit 10 # r, reword = use commit, but edit the commit message 11 # e, edit = use commit, but stop for amending 12 # s, squash = use commit, but meld into previous commit 13 # f, fixup = like "squash", but discard this commit‘s log message 14 # 15 # If you remove a line here THAT COMMIT WILL BE LOST. 16 # However, if you remove everything, the rebase will be aborted. 17 #
你更改pick的顺序,就决定了历史记录的顺序
3)多个提交压合一个
[email protected]:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -3 f10a4b93c8bbc834b644295ea2341cd6690bf954 test5 954ba575dc29decdb4642d83421dcf3c7cfe2192 Revert "test4" bcf6a96ef4dba4ee819ce357864911aa60458ae7 test4 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git rebase -i bcf6a96ef4dba4ee819ce357864911aa60458ae7 [detached HEAD 20ac46d] Revert "test4" 4 files changed, 3 insertions(+), 1 deletions(-) create mode 100644 2.txt create mode 100644 3.txt delete mode 100644 4.txt create mode 100644 branch.txt Successfully rebased and updated refs/heads/work. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -3 20ac46dd92113d8c40b33cb91402f6025551bef2 Revert "test4" bcf6a96ef4dba4ee819ce357864911aa60458ae7 test4 69b0c2e45258fcf33203f25444d562a9470092d7 revert test1 and test2 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --stat 20ac46dd92113d8c40b33cb91402f6025551bef2 commit 20ac46dd92113d8c40b33cb91402f6025551bef2 Author: zhangshuli <[email protected]> Date: Mon Mar 2 16:22:06 2015 +0000 Revert "test4" This reverts commit 2bc646d2f078f3c03ab5352a13a057fccc83621d. Revert "revert test1 and test2" This reverts commit 69b0c2e45258fcf33203f25444d562a9470092d7. test5 Change-Id: I09af8b31eb2d07cba0949042e06e09b85d597b7d 2.txt | 1 + 3.txt | 1 + 4.txt | 1 - branch.txt | 1 + 4 files changed, 3 insertions(+), 1 deletions(-)
这个其实就是在修改历史记录的基础上进行了第二次修改,如下
1 pick f4c241d test 3 2 pick 99298bc revert test1 and test2 3 pick 3e92336 test4 4 pick dd6f1ea Revert "test4" 5 6 # Rebase ab43af6..dd6f1ea onto ab43af6 7 # 8 # Commands: 9 # p, pick = use commit 10 # r, reword = use commit, but edit the commit message 11 # e, edit = use commit, but stop for amending 12 # s, squash = use commit, but meld into previous commit 13 # f, fixup = like "squash", but discard this commit‘s log message 14 # 15 # If you remove a line here THAT COMMIT WILL BE LOST. 16 # However, if you remove everything, the rebase will be aborted. 17 #
修改
1 pick f4c241d test 3 2 squash 3e92336 test4 3 pick 99298bc revert test1 and test2 4 pick dd6f1ea Revert "test4" 5 6 # Rebase ab43af6..dd6f1ea onto ab43af6 7 # 8 # Commands: 9 # p, pick = use commit 10 # r, reword = use commit, but edit the commit message 11 # e, edit = use commit, but stop for amending 12 # s, squash = use commit, but meld into previous commit 13 # f, fixup = like "squash", but discard this commit‘s log message 14 # 15 # If you remove a line here THAT COMMIT WILL BE LOST. 16 # However, if you remove everything, the rebase will be aborted. 17 #
结果
[email protected]7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -5 dd6f1ea300a8314c76fae3854291ace572f28391 Revert "test4" 3e92336ac3044d64b17c424eba01682234b14ff4 test4 99298bc028c9f9e45cc54302a371c729c8d4dd57 revert test1 and test2 f4c241ddb521ad85605687734addaac3887c4a4e test 3 ab43af6847f07d08a6c14cb211ce4007782202f5 Revert "test 1" [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git rebase -i ab43af6847f07d08a6c14cb211ce4007782202f5 [detached HEAD c294d73] test 3 2 files changed, 2 insertions(+), 0 deletions(-) create mode 100644 3.txt create mode 100644 4.txt Successfully rebased and updated refs/heads/work. [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --pretty=oneline -5 d69bd5c2f63bf3101816263c5325507010d6f8cc Revert "test4" 35942e8e4ef640804ada6e19bc8f62364892333a revert test1 and test2 c294d73f0d977b02686712b935572c486c478201 test 3 ab43af6847f07d08a6c14cb211ce4007782202f5 Revert "test 1" c7bc7ced616685852b0b225042f34c038979ade4 test 2 [email protected]-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$
4)一个提交分为多个提交
这个具体有什么作用还不清出,以后遇到了再说吧
时间: 2024-09-30 00:51:42