The git reset
command is a powerful command that is used to undo changes in a Git repository. There are three main forms of the git reset
command, which correspond to the three trees that Git maintains: --soft
, --mixed
, and --hard
.
git reset --soft <commit>
: This command moves the HEAD pointer to a specified commit, but leaves the staging area and the working directory unchanged. This means that the changes from the commits which are ahead of the current commit will be kept in the staging area.
git reset --mixed <commit>
or git reset <commit>
: This is the default mode. This command moves the HEAD pointer to a specified commit, and also changes the staging area to match this commit. However, the working directory is left unchanged. This means that the changes from the commits which are ahead of the current commit will be kept in the working directory but not staged.
git reset --hard <commit>
: This command moves the HEAD pointer to a specified commit, and also changes the staging area and the working directory to match this commit. This means that the changes from the commits which are ahead of the current commit will be discarded.
Please note that git reset
should be used with caution, especially the --hard
option, as it permanently discards commits and changes. It is also worth noting that git reset
is not the only way to undo changes in Git - depending on your use case, other commands like git revert
or git restore
might be more appropriate.
For more detailed usage, you can refer to the official Git documentation or use git reset --help
.