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-file [options] [tree-ish] file...
PARAMETERS
file...
One or more files to be reset. These paths are relative to the project root.
tree-ish
Optional. The commit or tree from which to restore the file's content. If omitted, it typically defaults to HEAD (the latest commit on the current branch). This can be a branch name, commit hash, tag, etc.
--staged
When used, it implies resetting the file in the staging area (index) to match the specified tree-ish (or HEAD), while keeping the working tree file unchanged. Effectively unstages the file.
--worktree
When used, it implies resetting the file in the working directory to match the staging area (index) or the specified tree-ish (or HEAD). This action discards local modifications.
--source=tree-ish
An explicit way to specify the tree-ish (commit, branch, tag, etc.) from which to restore the file. This clarifies the source for the file content.
DESCRIPTION
The command git-reset-file is not a standard, officially distributed Git command.
However, the concept it implies – restoring a single file to a previous state – is a fundamental Git operation. This functionality is typically achieved using the standard Git commands git restore or git checkout.
Conceptually, git-reset-file would allow users to:
- Unstage changes for a specific file, moving it from the Git index (staging area) back to the working directory without discarding local modifications. This is analogous to `git reset HEAD
`. - Discard local modifications in the working directory for a file, reverting it to its state in the Git index or the HEAD commit. This is analogous to `git restore
` (or `git checkout -- `). - Restore a file to its state from an arbitrary commit. This is analogous to `git restore --source=
` (or `git checkout -- `).
The primary purpose is to selectively revert changes to individual files without affecting other files or the overall repository history.
CAVEATS
The command name git-reset-file is not a standard part of the official Git distribution. Users typically achieve this functionality using git restore (recommended for newer Git versions) or git checkout -- for discarding working directory changes, and git reset HEAD for unstaging. Direct usage of git-reset-file would imply a custom script or alias defined by the user or a third-party tool.
DIFFERENCE FROM 'GIT RESET'
It's crucial to differentiate this conceptual `git-reset-file` operation from the general git reset command without a path. git reset (without file paths) typically moves the HEAD pointer and potentially rewrites history, affecting commits, branches, and potentially requiring a force push if pushed to a shared remote. git-reset-file (or its functional equivalents like git restore or git reset HEAD file) only affects the state of specific files in the working directory or staging area, without altering the commit history.
HISTORY
The ability to restore or unstage individual files has been a core Git feature since its inception. Historically, git checkout -- file was the primary command for discarding working directory changes to a file, and git reset HEAD file for unstaging.
With Git version 2.23 (released August 2019), the new command git restore was introduced to provide a clearer and safer interface for these operations, separating the concerns of restoring files from switching branches (which git checkout also does).
While git-reset-file itself does not have a formal history, its implied functionality evolved significantly with the introduction of git restore, making the process of individual file restoration more intuitive and less ambiguous.
SEE ALSO
git restore(1), git checkout(1), git reset(1)