These are two of the most common uses of git reset.īe careful when passing a commit other than HEAD to git reset, since this re-writes the current branch’s history. On the other hand, if you want to completely throw away all your uncommitted changes, you would use git reset -hard HEAD. For instance, git reset -mixed HEAD has the affect of unstaging all changes, but leaves them in the working directory. These flags are often used with HEAD as the parameter. It’s easier to think of these modes as defining the scope of a git reset operation:
![revert single file to master git revert single file to master git](https://micaic.com/dil/hkZCHnXbIFBzHxFVobu86AHaD9.jpg)
When you don’t include a file path as a parameter, they operate on whole commits. The parameters that you pass to git reset and git checkout determine their scope. Keep these components in mind as you read through this article. It helps to think about each command in terms of their effect on the three main components of a Git repository: the working directory, the staged snapshot, and the commit history. Hopefully, you’ll walk away with the confidence to navigate your repository using any of these commands. In this article, we’ll compare the most common configurations of git reset, git checkout, and git revert. They all let you undo some kind of change in your repository, and the first two commands can be used to manipulate either commits or individual files.īecause they’re so similar, it’s very easy to mix up which command should be used in any given development scenario.
![revert single file to master git revert single file to master git](https://www.bemyaficionado.com/wp-content/uploads/2020/06/image-3.png)
The git reset, git checkout, and git revert command are some of the most useful tools in your Git toolbox.