Git
EGit
version control
revert changes
Git tutorial

How to make a simple revert work on Git / EGit?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

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:

  1. 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.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions