Undoing Changes
Section 5: Undoing Changes
Section 5: Undoing Changes
Undoing Commits with git revert
Undoing Commits with git revert
Reverting the Last Commit
Reverting the Last Commit
To create a new commit that undoes the last commit:
git revert HEAD
Reverting a Specific Commit
Reverting a Specific Commit
To revert a specific commit (replace COMMIT_HASH):
git revert COMMIT_HASH
Resetting Commits with git reset
Resetting Commits with git reset
Soft Reset
To undo the last commit but keep changes staged:
git reset --soft HEAD^
Mixed Reset
Mixed Reset
To unstage changes as well:
git reset --mixed HEAD^
Hard Reset
Hard Reset
To discard changes entirely:
git reset --hard HEAD^
Stashing Changes with git stash
Stashing Changes with git stash
Stashing Changes
To stash changes:
git stash
Applying Stashed Changes
To apply stashed changes:
git stash apply
Clearing Stashes
To clear stashes:
git stash clear
This section covers undoing changes in Git, both at the commit level using git revert and git reset, and at the working directory level using git stash. Understanding these commands is essential for managing mistakes and refining the commit history.