Reverting a Commit
If you want to reverse the effects of a commit without rewriting the project history, thegit revert command is the best option. For example, suppose you committed the addition of a third story (i.e., adding third_story.md), but later determined that change should be undone. Running the command below will generate a new commit that cancels out the changes introduced by the specified commit:

third_story.md—while preserving your project’s commit history.
Using
git revert is particularly helpful in collaborative environments because it maintains the integrity of shared history.Resetting a Commit
Another method to undo changes is by using thegit reset command. The reset command comes in multiple forms, allowing you to either preserve or discard the changes made in a commit.
Soft Reset
A soft reset moves the branch pointer back to a previous commit without altering the working directory or staging area. This approach lets you review and re-commit the changes if needed. For example, to reset the last commit (which addedthird_story.md) while keeping its changes staged, execute:
Hard Reset
In contrast, a hard reset moves the branch pointer and discards all changes in the working directory related to the commit. Using a hard reset for thethird_story.md commit will completely remove the file:
A hard reset is irreversible for local changes. Ensure you truly want to discard all modifications before using this command.
Summary
Using these commands effectively enables you to manage your commit history and maintain a clean project state.
Happy coding, and see you in the next article!
For more detailed Git documentation, visit the Git Documentation. Enjoy your Git journey!