Toll free (US) : +1 (888) 838-3532 | NYC: +1 (646) 491-6866

If you want to revert the last commit, you can do it by single command.

First make sure what you really want to do, simply remove commit from repo or vanish all the last committed code.

So choose one of the below command as per requirement:

git reset HEAD~1

This will return your repository to its state before the git add commands that staged the files. Your changes will be in your working
directory. HEAD~1 refers to the commit below the current tip of the branch.

If you want to remove N commits but keep the code changes in your working directory, then run below command:

git reset HEAD~N

If you want to completely remove your latest commit and do not want to keep the code as well, you can go for a hard reset:

git reset –hard HEAD~1

Similarly, if you want to remove the last N commits and do not want to keep the code changes:

git reset –hard HEAD~N

Thanks!!

Railscarma as the leading ruby on rails development company delivers you with ruby on rails application development by employing an agile project management and delivery model, with all the flexibility for you to choose from multiple engagement models to help you save on your costs further. Let us know in details about your enterprise RoR Application development needs and our experts will show you how we can make it efficient and cost-effective for your business. Contact us with you queries and concerns and our experts will get right back to you.