Posts

Showing posts with the label restore

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 ...

How to recover all files in folder from specific branch

How to recover all files in folder from specific branch To recover all files in a folder from a specific branch to your current working tree, use the git checkout or git restore command, specifying the branch name and the path to the folder.   Run this command from your terminal:  git checkout <branch-name> -- <folder-path> For a safer, modern alternative (available in Git 2.23+), you can use Git Restore Documentation :  git restore --source = <branch-name> --staged --worktree -- <folder-path> How It Works <branch-name> : The name of the branch containing the files you want to recover. <folder-path> : The relative path to the folder (e.g., src/components/ ). The double dash ( -- ) : Tells Git to treat everything after it as a file or directory path, rather than a branch name. Once the command is run, the files will be placed into your working directory, staged, and ready to be committed