![Forrest logo](/images/logo.png)
git-reset:tldr:71b93
The command git reset --hard
is used to reset the current branch and the working directory to a specific commit in the Git history.
To explain it in more detail:
git reset
is a command that allows you to manipulate the branch history in Git.--hard
is a flag that specifies the type of reset you want to perform. In this case,--hard
means that the reset will be done forcefully, discarding any changes in the working directory and staging area.
When you execute git reset --hard
, you need to provide an additional argument, which typically is a commit reference such as a commit hash, branch name, or tag. The branch and the working directory will then be set to the specified commit.
For example, if you have the commit history A-B-C-D-E, and you are currently on commit E, running git reset --hard C
will change the branch to point to commit C and discard all commits D and E. Additionally, any changes in the working directory and staging area (uncommitted changes) will be discarded as well, making your working directory match the state of commit C.
It's important to note that git reset --hard
is a powerful and irreversible command. It rewrites the Git history, discarding commits and changes. Hence, it should be used with caution, especially if you have uncommitted changes or if you are collaborating on a project with others.