git-reset-file
Restore tracked file's content from index
TLDR
Reset a file to HEAD
Reset a file to a specific commit
SYNOPSIS
git reset [--patch] file...
PARAMETERS
--patch
Interactively choose which hunks to unstage.
file...
The paths to the files to unstage.
DESCRIPTION
The `git reset-file` command unstages changes from a specific file in the working tree, effectively removing it from the staging area (index) without modifying the file itself. It's like undoing a `git add` for a specific file. This command allows you to selectively remove changes before committing them, providing fine-grained control over your staged changes. The command updates the index to match the specified commit (HEAD by default), so if HEAD is the branch, the changes get un-staged but will still exist as changes in the working copy.
CAVEATS
This command operates on the index (staging area). It doesn't modify the working directory's content. If you want to revert the working copy, you'll need to use other commands such as `git checkout` or `git restore`.
It is important to ensure that you are in a git repository. If you are not git will not acknowledge this command is even a valid one
USE CASES
Commonly used before a `git commit` to remove accidentally staged changes or to split large changes into smaller, more manageable commits. It enables you to refine the changes included in your next commit.
EXAMPLES
Unstage a single file:
`git reset HEAD file.txt`
Unstage multiple files:
`git reset HEAD file1.txt file2.txt file3.txt`
HISTORY
The `git reset-file` functionality was introduced as part of the broader `git reset` command and separated to improve usability. The separate function allows for the selective un-staging of files without affecting the whole project index. It is commonly used when preparing commits with staged and unstaged changes and you decide to commit only a subset of staged changes.