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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:41:37  来源:igfitidea点击:

Git Copy a folder from master branch to another branch

gitgithub

提问by user2579475

I have folder name utilsI want to copythis folder from masterbranch to workbranch. 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 masterafter 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 pushas necessary. Git's output in your project may be different; I just made a simple test repo here with only one file in the utilsdirectory.

然后你可以git push根据需要。Git 在你的项目中的输出可能会有所不同;我只是在这里做了一个简单的测试 repo,utils目录中只有一个文件。