Git how to remove the last commit from remote and local. Sometimes we are creating the mistake on written commit message or push wrong code by mistake at the time we need to remove that code or commit from remote and local. So let’s see the step for removing the last commit from remote or local.
Make sure before removing any comment from the remote server because that commit also removed for your team member when his push or pull the code from the remote server.
First of all get the git log
The output will look like this on your command prompt
commit 6488b7e23c31f4472b063b8d3c3e15f8dfc91495 Author: thecodingstuff <email@example.com> Date: Thu Jul 20 10:17:39 2017 -0700 Add welcome heading tag commit 69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33 Author: thecodingstuff <firstname.lastname@example.org> Date: Thu Jul 20 10:14:36 2017 -0700 first commit
Now copy the commit id like “69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33” from where you want to remove commit on remote or local server.
Now type below command for removing the commit.
git reset --hard 69f7c2b25ccf49dcd9ede9f21d33eb5c2b6e6f33 git push -f origin master
Replace “master” with your branch name.
After following this command your commit was removed from the remote and local server.
If you face any issue after using the above steps please write the comment below.