Git: copy all files in a directory from another branch

。_饼干妹妹 提交于 2019-11-27 09:16:28

问题


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

I can then copy all of the files individually by doing

git checkout master -- dirname/filename

However, using wildcards has so far been a total fail. This does nothing:

git checkout master -- dirname/*.png

Though I guess I can use a bash script to do that, there has to be an easier way, right?


回答1:


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



回答2:


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')


来源:https://stackoverflow.com/questions/2668886/git-copy-all-files-in-a-directory-from-another-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!