While developing software, you may run into a situation where a specific commit breaks functionality and undoing that commit will fix up the functionality.
Step 1: Find the Commit Hash
To revert a commit in Git, we need to first find the hash associated with the commit that holds the breaking functionality. To do this, run the following command:
This will show something like the following:
johns-mbp /A/M/h/D/W/w/wpmerchant> git log commit 9499b5cdec92c100af1416425c1fe16c3ec8fd9420 (HEAD -> regular, origin/regular) Author: Ben Shadle <firstname.lastname@example.org> Date: Tue Jul 17 23:07:59 2018 -0700 update style of stripe elements commit 9455b5cdec92c100af1416425c1fe16c3ec8fd9420 (HEAD -> regular, origin/regular) Author: Ben Shadle <email@example.com> Date: Tue Jul 17 23:07:59 2018 -0700 update enqueueing of stripe elements commit c37839117ed9880a85334d723ae3bf5168d9eee135d0 Author: Ben Shadle <firstname.lastname@example.org> Date: Sun Jul 16 23:24:54 2017 -0700 update payment form styling
The payment form styling commit broke the styling of an unrelated element, so we want to revert it. So, the commit hash that we want is c37839117ed9880a85334d723ae3bf5168d9eee135d0.
Step 2: Revert a Commit Git
Run the following command to revert the ‘update payment form styling’ commit.
git revert c37839117ed9880a85334d723ae3bf5168d9eee135d0
That’s all she wrote!