Revert changes in Git

Learn how to revert a committed change in Git to either a specific branch or the default branch, so you can fix bugs or undo unwanted changes.

  • Difficulty: Beginner

  • Estimated time: 15 minutes

  • Prerequisites: Basic understanding of Git

While some Git platforms provide user interfaces for reverting changes, it is recommended to perform reverts directly from the local system using Git commands for greater control and accuracy.

  • Open your application’s Git repository and clone it to your local machine.

  • Switch to the branch to which you want to revert a change:

git checkout <branch-name>
  • To see the commit history, use the following command:

git log

This command lists commits in reverse chronological order, starting with the latest. Each commit entry shows details such as the commit hash, author, date, and message.

  • To revert a commit, use the git revert command followed by the specific commit hash.

Example

To revert to a single commit:

git revert a041f66990c3610982a8477d05931ac6a1636813

To revert multiple commits, use a range of commit hashes:

git revert a041f66990c3610982a8477d05931ac6a1636813^..3ce6a7e9a6d1e06eacec4c5b4ffca53d0eb7a3f9

Make sure you revert changes from the most recent commit first.

Many Git platforms, such as GitHub and GitLab, offer graphical interfaces that allow you to revert changes directly on their platforms.

  • If conflicts arise during the revert process, resolve them manually by editing the conflicting files and then continuing the revert.

  • After resolving any conflicts, commit the changes and push them to your remote Git repository.

  • Once the changes are committed, pull them into the Bonita UI Builder application to apply the updates.