How to make a simple revert work on Git / EGit?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Git is a powerful distributed version control system used by developers worldwide to manage and track changes in their codebase. EGit is a plugin for the Eclipse IDE that provides Git integration within the Eclipse development environment. One common task developers may need to perform in Git is reverting changes. This article provides a detailed explanation of how to revert changes using both the Git command line and EGit in Eclipse.
What Does Reverting Mean in Git?
Reverting in Git means creating a new commit that undoes changes made in a previous commit. Unlike "reset," which moves the current branch to a specific state and can potentially lose commits, "revert" is a safer operation that preserves the entire commit history.
How to Revert a Commit in Git
Reverting in the Terminal
Performing a revert in Git via the terminal is straightforward:
- Identify the Commit Hash: Run `git log` to find the commit hash you want to revert.
- Conflicting Changes: Reverting can lead to merge conflicts if subsequent changes affect the same lines of code.
- Revert vs. Reset: Unlike `git reset`, which alters the commit history, `git revert` is non-destructive and ideal for shared branches where preserving history is crucial.
- Reverting Multiple Commits: Multiple commits can be reverted either by manually reverting them one by one or by using a range in more advanced scenarios.
- Amending Commits: If you've just made a commit and realize you need to amend, you can use `git commit --amend` for quick fixes rather than reverting.
- Reverting Merge Commits: When reverting a merge commit, use `git revert -m ``<mainline>`` ``<commit-hash>``` to specify the parent’s mainline.

