EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

Git 刪除最新 commit 並同步至遠端的兩個簡單命令

在使用 Git 進行版本控制時,如果你需要刪除最新的 commit 並同步到遠端,只需要使用以下兩個命令:

 

  1. 重置本地到上一個 commit 並刪除最新的改動:
git reset --hard HEAD^

這條命令會將本地的狀態回退到上一次提交,徹底刪除最新的 commit 和改動。

 

  1. 強制推送到遠端:
git push --force

使用這條命令強制推送更改到遠端倉庫,讓遠端與本地同步,從而刪除遠端的最新 commit。

 

請注意,使用 --force 會重寫遠端倉庫的歷史,因此在多人協作時,務必謹慎使用,避免造成衝突或其他影響。

 

GitBash使用手冊

This article was last edited at 2024-10-22 10:20:51

Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).

There is 14h41m12s left until you can comment.