Git Revert and Git Reset are two important commands in Git for undoing and adjusting changes in the commit history of a repository. Here is a guide on how to use Git Revert and Git Reset:
Git Revert
-
Git Revertallows you to create a new commit to undo (revert) previously committed changes. -
To
revertacommit, use the following command:git revert <commit_id>Replace
<commit_id>with the ID of thecommityou want to revert. A newcommitwill be created, undoing the changes in the selectedcommit. Revertdoes not alter thecommithistory but creates a newcommitto revert the changes.
Git Reset
-
Git Resetallows you to go back to a previous state by moving theHEADand current branch to a specific commit. -
Git Resethas three different modes:--soft, --mixed (default), and --hard. -
To
resettheHEADand current branch to acommit, use the following command:git reset --mode <commit_id>Replace
<commit_id>with the ID of thecommityou want to reset to. -
Git Resetmodes:-soft:Moves theHEADand current branch to the specifiedcommit, keeping the changes of the previouscommitin the staging area. Use the commandgit reset --soft <commit_id>.--mixed:This is the default mode. Moves theHEADand current branch to the specified commit and removes the changes of the previouscommitfrom the staging area. Use the commandgit reset --mixed <commit_id>.--hard:Moves theHEADand current branch to the specifiedcommitand discards all changes of the previouscommit. Be cautious when using it, as any uncommitted changes will be lost. Use the commandgit reset --hard <commit_id>.
<commit_id>. Git Resetalters thecommithistory and can result in data loss, so use it with caution.
Git Revert and Git Reset are powerful tools for undoing and adjusting the commit history in Git. Use them carefully to ensure project stability and avoid data loss.

