git 時光機倒回過去或指定版本

1/12/2024 Git

# 取消此次 commit ,並保留檔案變更

  git reset HEAD~1

PS. 如果想要回復成上 2 個,就做 2 次此指令

# 查看所有操作紀錄

  git reflog

PS. 紀錄包含 pull、commit、reset ...的所有操作紀錄 image

# 復原到指定版本

  git reset --hard {commit id}

image

# 修改指定 commit 的訊息,而不影響 commit 內容紀錄

EX:要修改倒數第 3 個 commit 的訊息

  git rebase -i HEAD~3
最後更新: 7/24/2025, 8:50:37 AM