已經commit ,還沒有push到倉庫,撤銷該提交
換句話:撤銷最近一次提交,並將上該此提交的內容放在暫存區
第一步:
git log
查看提交的記錄
$ git log
commit bb6393c54d764d654590cd6195eb20d87c6313ac (HEAD -> main)
Author: shanzm_aimer <[email protected]>
Date: Fri Nov 24 17:01:45 2023 +0800
2023年11月24日 17:01:41-Update
commit 510053f74a12b3f8f55e1129ce0249402cbd6f84 (origin/main, origin/HEAD)
Author: shanzm_aimer <[email protected]>
Date: Tue Oct 24 16:48:50 2023 +0800
2023年10月24日 16:48:26-Update:移動報修兩化融合演示版本
第二步:
最近一次提交(CommitId:bb6393c5)是我們想要撤銷,並放在暫存區的
所以我們要在撤銷到(CommitId:510053f7)
git reset --soft 510053f7
第三步:
此時最近一次提交(CommitId:bb6393c5) 就會在暫存區,可以取消暫存
取消暫存,會保留最新本地的更改的
其實此時就相當於: git reset --maxed 510053f7
注1:reset 總VS中翻譯爲:重置
注2:reset 在Vs中有reset --maxed 和 reset --hard 按鈕,沒有 reset --soft命令的按鈕
注3:reset --hard CommitId 重置到CommitId提交,最後一次提交的和本地的所有修改都沒有了,慎用