Sitemap
AARUSHI TIWARI

AARUSHI TIWARI

Engineer - DevOps & Cloud

Git Rollback

2 min readNov 19, 2023

I had a very tough time understanding git commands, operations, etc. But no since I got it I will explain then in an easier and most nderstandable way. So, lets get started.

Git rollback is done whenever we want our previous commits to undo or ommited. There can be many time we commit the changes and then push them to our github from our local repository, but then we suddenly remmember… oh..no.. I was not supposed to push it there. During such problems our git has a solution that is we can rollback our prvious mistake. Let’s see how.

The commnds used during rollback are:

  1. git revert <commit_hash>
  2. git reset <commit_hash>

Git revert :- this command reverses the changes but leaves the commit. Revert is safer considering we can revert a revert.

step1 : find the commit hash using git log

Get AARUSHI TIWARI’s stories in your inbox

Join Medium for free to get updates from this writer.

step2 : revert the commit using the commit hash found git revert <commit-hsh>

step3 : push the changes git push origin <branch_name>

We can use git revert <commit ID> --no-edit as this command stops from opening the default editor from specifying the commit message.

Git reset :- This command revos the commit unlike in git revert where the commit remains. This command undoes the specific commit, changes, and staging. There are different modes of git reset they are --soft, --mixed (default), and --hard.

git reset --soft<commit> This mode does not touch the index of the working directory. It ony resets the head of the specific commit. Changes to this spcified commit are staged but not commited.

git reset <commit> This is the default one if no mode is specified. It resets te index to the specified commit while leaving the working directory unchanged.

git reset --hard <commit>This mode redirects the index and the working directory to a secified commit. It discards all the changes including the staged and ncommited changes.

git reset — soft HEAD~2 <name> and git reset — hard HEAD~2 <name>are the commands used to uncommit the last N commits in a specific directory.

That was all for git rollback for now

--

--