How do I cherry-pick the changes to only one file from a commit?
- First, find the commit hash you want to cherry-pick from
- Use this command:
git checkout <commit_hash> -- path/to/file
This will:
- Take the version of the specified file from the commit you want
- Stage those changes in your current branch
- You can then commit these changes normally with
git commit
Alternative method using git show
:
git show <commit_hash>:path/to/file > path/to/file