Git: copy all files in a directory from another branch

后端 未结 2 1216
余生分开走
余生分开走 2020-12-07 09:30

How do I copy all files in a directory from another branch? I can list all of the files in that directory by doing

git ls-tree master:dirname
相关标签:
2条回答
  • 2020-12-07 10:26

    As you are not trying to move the files around in the tree, you should be able to just checkout the directory:

    git checkout master -- dirname
    
    0 讨论(0)
  • 2020-12-07 10:26

    If there are no spaces in paths, and you are interested, like I was, in files of specific extension only, you can use

    git checkout otherBranch -- $(git ls-tree --name-only -r otherBranch | egrep '*.java')
    
    0 讨论(0)
提交回复
热议问题