Discuss / Git / 总结-回退

总结-回退

Topic source

回退

  • 工作区版本回退
 (use "git reset HEAD <file>..." to unstage)
  • 暂存区回退
 (use "git checkout -- <file>..." to discard changes in working directory)
  • 版本库回退
PS F:\learngit> git log --pretty=oneline                   //当前命令行git版本库修改
67a223be9a3e3d19cbffa7de2c66d55f2ef815f1 append GPL        
8a0a1d076e3dbd501ac22118a416d77694b3e11b add distributed
56238b3dee16086f0260ade88762d2a607f49860 This is frist edit

PS F:\learngit> git reset --hard HEAD^                    //回退到上一个版本   即使得HEAD回退到上一个版本  ^上一个 ^^上上个 ~100 上100个
HEAD is now at 8a0a1d0 add distributed

PS F:\learngit> git log --pretty=oneline                  
8a0a1d076e3dbd501ac22118a416d77694b3e11b add distributed
56238b3dee16086f0260ade88762d2a607f49860 This is frist edit

PS F:\learngit> git reset --hard 67a223                   //反悔之前修改  reset --hard <版本ID>
HEAD is now at 67a223b append GPL

PS F:\learngit> git reflog                               //如果关闭了之前版本号 ,查看之前的命令修改 reglog 
67a223b HEAD@{0}: reset: moving to 67a223
8a0a1d0 HEAD@{1}: reset: moving to HEAD^
67a223b HEAD@{2}: commit: append GPL
8a0a1d0 HEAD@{3}: commit: add distributed
56238b3 HEAD@{4}: commit (initial): This is frist edit

  • 1

Reply