TIL an Easy Way to Cherry Pick Files From Other Branches

I found myself in need of cherry-picking a file out of a different branch into master today and instead of actually using cherry pick and having to mess with reseting the stuff I don’t need and taking them out I found out you can simple checkout the file from your destination branch!

1
2
3
4
5
6
7
8
9
10
11
12
13
(master) % git checkout master
(master) % git checkout feature-branch CHANGELOG
(master)⚡ % git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#  modified:   CHANGELOG
#
(master)⚡ % git commit -m 'Cherry-picked from feature-branch'
[master dfdb2ba] Cherry-picked from feature-branch
1 file changed, 8 insertions(+)
(master) %
Git, TIL
Comments

Comments