1.撤销提交信息
首先,通过git log
查看提交信息,以便获取需要回退至的版本号:
<span style="color:#000000"><code class="language-shell">$ git log
commit a44822002522f2ab1e3a5e2a1cec00a7d3d02185 (HEAD -> master, origin/master, origin/HEAD)
Author: hanchao5272 <<span style="color:#006666 !important">89298141</span>@qq<span style="color:#009900 !important">.com</span>>
Date: Sun Mar <span style="color:#006666 !important">4</span> <span style="color:#006666 !important">11</span>:<span style="color:#006666 !important">14</span>:<span style="color:#006666 !important">55</span> <span style="color:#006666 !important">2018</span> +<span style="color:#006666 !important">0800</span>
CSDN-java反射<span style="color:#006666 !important">06</span>-成员变量Field-代码优化
commit aa909cff2239536df14820fe086d96305b24e9f1
Author: hanchao5272 <<span style="color:#006666 !important">89298141</span>@qq<span style="color:#009900 !important">.com</span>>
Date: Sat Mar <span style="color:#006666 !important">3</span> <span style="color:#006666 !important">23</span>:<span style="color:#006666 !important">43</span>:<span style="color:#006666 !important">03</span> <span style="color:#006666 !important">2018</span> +<span style="color:#006666 !important">0800</span>
CSDN-java反射-修饰符-代码优化
</code></span>
- 我们需要撤销CSDN-java反射06-成员变量Field-代码优化这次提交,所以需要回退至的版本是CSDN-java反射-修饰符-代码优化,即需要回退至的版本号是:aa909cff2239536df14820fe086d96305b24e9f1。
然后,通过git reset –soft <版本号>重置至指定版本的提交,达到撤销提交的目的:
- 参数soft指的是:保留当前工作区,以便重新提交
还可以选择参数hard,会撤销相应工作区的修改,一定要谨慎使用
然后,通过git log
确认是否成功撤销:
<span style="color:#000000"><code class="language-shell">$ git <span style="color:#000088 !important">log</span>
commit aa909cff2239536df14820fe086d96305b24e9f1 (HEAD <span style="color:#4f4f4f !important">-> </span>master)
Author: hanchao5272 <span style="color:#4f4f4f !important"><</span><span style="color:#006666 !important">89298141</span>@qq<span style="color:#4f4f4f !important">.</span>com<span style="color:#4f4f4f !important">></span>
<span style="color:#4f4f4f !important">Date</span>: Sat Mar <span style="color:#006666 !important">3</span> <span style="color:#006666 !important">23</span>:<span style="color:#006666 !important">43</span>:<span style="color:#006666 !important">03</span> <span style="color:#006666 !important">2018</span> <span style="color:#4f4f4f !important">+</span><span style="color:#006666 !important">0800</span>
CSDN<span style="color:#98c379">-java</span>反射<span style="color:#4f4f4f !important">-</span>修饰符<span style="color:#4f4f4f !important">-</span>代码优化
</code></span>
已经成功撤销。
2.撤销
通过git push origin master –force强制提交当前版本号,master是什么分支就写什么分支这里以master实力以达到撤销版本号的目的:
<span style="color:#000000"><code class="language-shell">$ git <span style="color:#000088 !important">push</span> origin master --force
Total <span style="color:#006666 !important">0</span> (delta <span style="color:#006666 !important">0</span>), reused <span style="color:#006666 !important">0</span> (delta <span style="color:#006666 !important">0</span>)
To github<span style="color:#009900 !important">.com</span>:hanchao5272/myreflect<span style="color:#009900 !important">.git</span>
+ a448220..<span style="color:#009900 !important">.aa</span>909cf master -> master (forced update)
</code></span>
必须添加参数force进行强制提交,否则会提交失败,并报错:
报错原因:本地项目版本号低于远端仓库版本号。