Git note - How to checkout specific commit - Git 如何checkout 之前的Commit / Changeset

常常很大意地 merge完一些程式碼後沒有測試便CommitPull 了到 Remote Repo 所以便要用 一些 git command 來還原之前的 Commit 再去解決問題

那麼如何 還原或 Checkout 之前的Commit 呢?

解決方法分簡單 我們只需要找到之前commit的 hash id 之後 “git checkout [commit hash]” 便可以了

查看之前的Commit 可以使用 “git log [-(前多小個 commit)]” e.g.

// 這個指令會輸出前三個commit的資訊
git log -3

Git Log 取後commit hash 之後 只要輸內前 8 個以上的 characters 應該便足夠令 git 識出那個commit你想checkout的 之後可以checkout 這個 commit 了

git checkout 7aef7c3f

Local Repos 的 程式碼應該會還原到這個commit 時的 程式碼

hope you find it useful

Chi Yau
Chi Yau
Software Engineer

Interested on Learning new stuff and experience sharing