How to cherry pick only changes for only one file, not the whole commit

后端 未结 9 1345
萌比男神i
萌比男神i 2020-12-04 07:12

I need to apply changes introduced in one branch to another branch. I can use cherry pick to do that. However, in my case I want to apply changes which are relevant only for

9条回答
  •  Happy的楠姐
    2020-12-04 07:19

    What I tend to do is to use git ls-tree

    just do:

    git ls-tree -r  |grep 'your filename'
    # there will be output that shows a SHA1 of your file
    git show ${SHA1 of your file} > 'your filename'
    

    This will print all filenames matching your grep and gives SHA1 keys of the files in the commit.

    Git show can be used on files outside of your branch as well. using > from your shell to pipe the output into a file gives you the result you are looking for.

提交回复
热议问题