Reverting or undoing git commits

Undoing git commits is almost always a bad idea. The only time you should contemplate really undoing a commit is if the commit contains information that should never ever be seen in the repository. For example if you accidentally commit a file containing sensitive password information.

In all other cases, let the history stay as history. If the commit needs to be 'undone', create a new commit with the appropriate correction. This approach will keep things simple and stop you or other users of the repository getting into trouble. There are lots of articles available covering using git reset to achieve this sort of thing but we do not want to lose the history, we just want to return the branch to an earlier state as its 'latest' revision:

So, how do you undo a change without rewriting history?

  1. 'git log' - Use the log to find the commits you need to undo.
  2. 'git revert <commit>' Undo the relevant commit (you can specify a range). If the commits involve merges you may need to specify the merge parent (typically 1, eg 'git revert dd33a78 -m 1')

This way the history remains consistent so you can recover from mistakes with correcting the mistakes. You can also relax knowing that only normal 'git pulls' are needed by other repository users to bring their working copies in line.

Comments 5 months, 1 week ago

Consultation and reversal of the theme are allowed for future passages. The rank of the is ensured for the turns. The utilization is felt by heart for the persons. Its impact is fit for the top of the goals for all humans.

Link | Reply

write my cv 3 weeks, 3 days ago

A few weeks ago, I made a mistake in my code that pretty much messed up all of my progress. It was late at night, and I didn't want to go back to the previous commit because there were tons of other changes in it that would make it extremely difficult for me to fix this problem. So instead, I just rewrote everything from scratch.

Link | Reply

here 22 hours, 8 minutes ago

Is there a git command to reverse or undo a commit? Yes, there is! In this blog post, we will discuss how to reverse or undo a git commit. We will also discuss how to rearrange pages in pdf using the pdfpages package. Happy reading!

Link | Reply

New Comment


required (not published)


Australia: 07 3103 2894

International: +61 410 545 357