You have a perfect git branch model, neatly dividing code between the release and the development or trunk branch. Now suddenly you realise that you need to use the file from the other branch. But you can’t merge the branch for that sake !! WTF !
git checkout !! help !
- Make sure the file that you want to pull is clean (ie. that file shouldn’t be shown as modified in git status)
$ git checkout <other-branch-name>/<commit-hash> -- path/to/the/file
You can now checkout the branch’s HEAD or that hash’s state of the file into your current working directory. You can now play with your file, add, commit. Done !
2 thoughts on “git merge specific files from another branch or revision”
That does not merge changes, it overwrites the code in the current branch with changes from the selected branch.
You are right, it checks-out – But wording is just the way a developer might think 😀