Undoing Changes with Git Reset
The git reset
command undoes changes by resetting the current branch to a specific state.
Example:
# Unstage a file
git reset HEAD file.txt
Reverting Commits
The git revert
command creates a new commit that undoes the changes of a previous commit.
Example:
# Revert a specific commit
git revert commit-hash
Detached HEAD State
In the detached HEAD state, you can view and make changes to previous commits without changing the branch.
Example:
# Checkout a specific commit (detached HEAD)
git checkout commit-hash
Restoring Files with Git Restore
The git restore
command restores working tree files to match the index or another commit.
Example:
# Restore a file to the last commit
git restore file.txt