How to revert changes to only specific file(s)?
How to revert changes to only specific file(s)? To revert changes to a specific file in Git, use git restore <file> for uncommitted changes or git checkout <commit> -- <file > to pull an older version from history. The correct command depends on whether your changes are saved, staged, or already committed. Uncommitted Changes Discard local edits in the working directory: git restore <file-path> Unstage a file while keeping your local edits: git restore --staged <file-path> Discard changes in both staged and working directories: git restore <file-path> Revert a file to how it looked in a past commit: git checkout <commit-hash> -- <file-path> Pull a specific file from another branch: git checkout <branch-name> -- <file-path> To revert a specific file that has already been committed, use git checkout or git restore with a specific commit hash. Overwrite the file and prepare a new commit This method changes ...