How to revert a Git commit?

QuestionsQuestions8 SkillsProYour First Git LabAug, 23 2025
0146

To revert a Git commit, you can use the git revert command followed by the commit hash you want to undo. Here’s the format:

git revert <commit_hash>

Steps to Revert a Commit:

  1. Identify the Commit Hash: Use git log to find the commit hash of the commit you want to revert.

    git log
  2. Revert the Commit: Use the git revert command with the commit hash.

    git revert <commit_hash>
  3. Edit Commit Message (Optional): If your default text editor opens, you can either accept the default commit message or modify it. Save and close the editor to finalize the revert.

Example:

If you want to revert a commit with the hash 3050fc0d3, you would run:

git revert 3050fc0d3

After executing this command, Git will create a new commit that undoes the changes made by the specified commit.

0 Comments

no data
Be the first to share your comment!