Git - revert repo to previous commit, when current code deployed went wrong

0 votes
added Nov 18, 2021 in Git by lcjr First Warrant Officer (9,190 points)

This usually happened when current push or deployed code is contains error. Best thing to do? revert to previus commit.

git log 

// the following logs appear and choose which to use e.g
commit 31eb090365b9d177880f66beee2312ad2e130e3a (origin/master, origin/HEAD, master-bak, master)

//checkout to new commit point to revert temporarily
git checkout 31eb090365b9d177880f66beee2312ad2e130e3a


Another method is, create bak branch e.g

git branch master-bak

//once master is bad, checkout to master-bak, the previous state of commit. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.