Git 刪除最新 commit 並同步至遠端的兩個簡單命令
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/1059
在使用 Git 進行版本控制時,如果你需要刪除最新的 commit 並同步到遠端,只需要使用以下兩個命令:
- 重置本地到上一個 commit 並刪除最新的改動:
git reset --hard HEAD^
這條命令會將本地的狀態回退到上一次提交,徹底刪除最新的 commit 和改動。
- 強制推送到遠端:
git push --force
使用這條命令強制推送更改到遠端倉庫,讓遠端與本地同步,從而刪除遠端的最新 commit。
請注意,使用 --force 會重寫遠端倉庫的歷史,因此在多人協作時,務必謹慎使用,避免造成衝突或其他影響。
This article was last edited at 2024-10-22 01:20:51