Git 将一个文件夹从 master 分支复制到另一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17999851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Copy a folder from master branch to another branch
提问by user2579475
I have folder name utils
I want to copy
this folder from master
branch to work
branch. How do I do that ?
我有文件夹名称,utils
我想将copy
这个文件夹从一个master
分支转移到work
另一个分支。我怎么做 ?
回答by Carl Norum
To copy the folder over:
复制文件夹:
$ git checkout work
Switched to branch 'work'
$ git checkout master -- utils
$ git add utils
$ git commit -m "Adding 'utils' directory from 'master' branch."
[work 9fcd968] Adding 'utils' directory from 'master' branch.
?1 file changed, 0 insertions(+), 0 deletions(-)
?create mode 100644 utils/file
If you want to delete it on master
after that:
如果你想在那master
之后删除它:
$ git checkout master
Switched to branch 'master'
$ git rm -r utils
rm 'utils/file'
$ git commit -m "Removing 'utils' directory."
[master c786f95] Removing 'utils' directory.
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 utils/file
Then you can just git push
as necessary. Git's output in your project may be different; I just made a simple test repo here with only one file in the utils
directory.
然后你可以git push
根据需要。Git 在你的项目中的输出可能会有所不同;我只是在这里做了一个简单的测试 repo,utils
目录中只有一个文件。