git撤回push到远程的代码

git如何撤回已经commit 并且push到远程的代码;

使用 git log 或 git log path/to/ 后,git一直停留在log模式,这时只需要按 q 键即可退出

$ git log
commit 4a2308de3ea1e3d2519508fa6ba60277ed522350 (HEAD -> master, origin/master, origin/HEAD)   

Author: Office client <[email protected]>
Date:   Mon Apr 4 14:56:27 2020 +0800

commit 08fb116064eef9143167259257f4eccbcc1ff363         

Author: Office client <[email protected]>
Date:   Mon Apr 4 10:39:03 2020 +0800

commit b0f46733196e19cdca9fe2c2677ef364ec5ad189 

Author: Office client <[email protected]>
Date:   Mon Apr 2 10:39:03 2020 +0800

红色的是刚刚push到远程的记录。

现在需要回滚到黄色的版本

$ git reset --soft 08fb116064eef9143167259257f4eccbcc1ff363
$ git log

commit 08fb116064eef9143167259257f4eccbcc1ff363     

Author: Office client <[email protected]>
Date:   Mon Apr 4 10:39:03 2020 +0800

commit b0f46733196e19cdca9fe2c2677ef364ec5ad189     

Author: Office client <[email protected]>
Date:   Mon Apr 2 10:39:03 2020 +0800

最上面红色标记的 4a2308de3ea1e3d2519508fa6ba60277ed522350已经查不到了,这表示撤销成功了。

这个时候将本地的代码强制push到远程。

$ git push origin master --force

你可能感兴趣的:(Git/SourceTree,git)