git config core.logallrefupdates
true
本方法只适合本地仓库操作
第一种:
jagent@ubuntu:~/xin/mytest$ git log --oneline
6c8826b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
989c771 1
4302e9b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
fa2e467 patch 3
9f574c8 patch 2
3d4d66d patch 1
7c4368e begin
jagent@ubuntu:~/xin/mytest$ git reset --hard 9f574c8
HEAD is now at 9f574c8 patch 2
jagent@ubuntu:~/xin/mytest$ cat .git/logs/refs/heads/master
0000000000000000000000000000000000000000 6c8826b6580eb82344b087f4ba3a76893ca5919c xwx496887 <xwx496887@notesmail.huawei.com> 1604559710 +0800 clone: from ssh://xwx496887@10.148.192.216:29418/ST/mytest
6c8826b6580eb82344b087f4ba3a76893ca5919c 9f574c85dda8786f87515c713dfd8558248928d1 xwx496887 <xwx496887@notesmail.huawei.com> 1604559810 +0800 reset: moving to 9f574c8
jagent@ubuntu:~/xin/mytest$ git reset --hard 6c8826b6580eb82
HEAD is now at 6c8826b TicketNo:DTS2020062200775
jagent@ubuntu:~/xin/mytest$ git log --oneline
6c8826b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
989c771 1
4302e9b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
fa2e467 patch 3
9f574c8 patch 2
3d4d66d patch 1
7c4368e begin
这样恢复原来的提交了,中间省略了git reset --hard 9f574c8 的git log
第二种方法
jagent@ubuntu:~/xin/mytest$ git log --oneline
6c8826b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
989c771 1
4302e9b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No
fa2e467 patch 3
9f574c8 patch 2
3d4d66d patch 1
7c4368e begin
jagent@ubuntu:~/xin/mytest$ git reset --hard 3d4d66d
HEAD is now at 3d4d66d patch 1
jagent@ubuntu:~/xin/mytest$ git log --oneline
3d4d66d patch 1
7c4368e begin
jagent@ubuntu:~/xin/mytest$ git reflog show master |head -5
3d4d66d master@{0}: reset: moving to 3d4d66d
6c8826b master@{1}: clone: from ssh://xwx496887@10.148.192.216:29418/ST/mytest
jagent@ubuntu:~/xin/mytest$ git reset --hard master@{1}
HEAD is now at 6c8826b TicketNo:DTS2020062200775
jagent@ubuntu:~/xin/mytest$ git log --oneline
6c8826b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or B
989c771 1
4302e9b TicketNo:DTS2020062200775 Description:ci test Team:ETCD1_CI Feature or B
fa2e467 patch 3
9f574c8 patch 2
3d4d66d patch 1
7c4368e begin