How to revert a commit?

QuestionsQuestions8 SkillsProYour First Git LabNov, 11 2025
0134

To revert a commit in Git, you can use the git revert command. This command creates a new commit that undoes the changes made by a specific commit without altering the commit history.

Steps to Revert a Commit:

  1. Identify the Commit: First, find the commit hash of the commit you want to revert. You can do this by running:

    git log
  2. Revert the Commit: Use the git revert command followed by the commit hash. For example:

    git revert <commit-hash>

    Replace <commit-hash> with the actual hash of the commit you want to revert.

  3. Commit Message: Git will open your default text editor to allow you to enter a commit message for the revert. You can modify it or keep the default message.

  4. Complete the Revert: Save and close the editor to complete the revert process.

Example:

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

git revert 3050fc0d3

This will create a new commit that undoes the changes introduced by the specified commit, preserving the history of your repository.

0 Comments

no data
Be the first to share your comment!