March 19, 2025

Photo Credit: Dall-E by OpenAI
Git Checkout Commit & Git Restore Branch
When working with Git, you might need to restore files/folders from a branch or a commit. Hereβs how to do it efficiently.
π Using git restore (Git 2.23+)
For restoring files/folders from a specific branch without switching branches:
git restore --source=<branch-name> -- <file/folder-path>Example:
git restore --source=develop -- src/config.jsonThis brings config.json from develop into the current branch without switching branches.
π Using git checkout (Git 2.23-)
For restoring files/folders from a specific branch without switching branches:
git checkout <commitSHA> -- <file/folder-path>Example:
git checkout <commitSHA> --source=develop -- src/config.jsonPeace... π