📌  相关文章
📜  git revert one commit - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:15:18.494000             🧑  作者: Mango

Git Revert One Commit - Shell-Bash

If you've committed something to your Git repository that you regret, or have found out that it breaks something you thought was working just fine, don't worry. Git has a built-in command that allows you to undo a commit: git revert.

What is git revert?

Git revert is a command that undoes the changes made by a specific commit, creating a new commit that undoes the previous change.

How to use git revert to undo a commit

To revert a commit, you will need to know the SHA hash of the commit you want to undo. You can find the SHA hash for your latest commit by typing the following command in your terminal:

$ git log

This will list out all the commits made to your repository, with the latest commit listed at the top. Find the commit you want to revert and copy its SHA hash.

Once you have the SHA hash, type the following command in your terminal:

$ git revert [SHA hash]

For example, if your SHA hash is 'abc123', the command would be:

$ git revert abc123

Git will then create a new commit that undoes the changes made by the commit with the SHA hash you provided.

Conclusion

Git revert is a handy command that allows you to undo changes made by a specific commit. By using git revert, you can easily fix mistakes and keep your repository clean without having to resort to complex branching and merging strategies.