Git将文件夹从主分支复制到另一个分支

use*_*475 38 git github

我有文件夹名称utils我想copymaster分支到work分支这个文件夹.我怎么做 ?

Car*_*rum 69

要复制文件夹:

$ 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
Run Code Online (Sandbox Code Playgroud)

如果你想在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
Run Code Online (Sandbox Code Playgroud)

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

  • 仅仅考虑一下,当`work`和`master`再次合并时会发生冲突,因为每一方都发生了不同的操作. (3认同)