git-revert is a command in the Git version control system used to undo changes introduced by commits. It creates a new commit that inverts the changes made by the commit being reverted, rather than deleting or modifying the history of the repository. Here are some key points regarding git-revert:
-
Function: git-revert does not erase the commit from the history but instead creates a new commit that undoes the changes of the specified commit. This approach maintains the integrity of the project's history, which is particularly useful in shared repositories where rewriting history could cause conflicts.
-
Usage: The basic syntax is:
git revert [commit-hash]
Where [commit-hash]
is the SHA-1 identifier of the commit you want to revert.
-
History: git-revert was introduced early in the development of Git, around the time when Git was first released in 2005 by Linus Torvalds. It was designed to handle situations where reverting a change was necessary without altering the history of commits, which is crucial for collaborative workflows.
-
Context: This command is particularly useful:
- When you need to undo a commit that has already been pushed to a shared repository.
- To backtrack on a feature or fix that was later found to be incorrect or unnecessary.
- For compliance with policies that prohibit changing history in branches like 'main' or 'master'.
-
Options:
--no-commit
: Stops the reversion process before creating a new commit, allowing you to make additional changes or commit manually.
-n
or --no-edit
: Uses the default commit message or allows editing it before committing.
External Links:
Related Topics: