如何合并git中的子目录? [英] How do I merge a sub directory in git?

查看:125
本文介绍了如何合并git中的子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以合并仅从本地git分支到远程git分支的子目录的更改,还是全部或全部?

例如,我有:

 分支-a 
- 内容-1
- dir-1
- content-2



  branch-b 
- content-1
- dir-1
- `content-2

我只想将branch-a dir-1的内容与branch-b dir-1的内容合并。

解决方案

就像SO问题的替代方法如何合并选择性文件和git-merge?,我刚刚发现这个GitHub线程可以更适应mer根据 git创建整个子目录阅读树



  • 我的存储库=> cookbooks

    我的存储库目标目录=> cookbooks / cassandra


  • 远程存储库=> infochimps

    远程存储库源我想合并到 cookbooks / cassandra => infochimps / cookbooks / cassandra




以下是我用来合并它们的命令


  • 添加存储库并获取它




 
git remote add -f infochimps git://github.com/infochimps/cluster_chef.git





  • 执行合并




 
git merge -s我们的--no-commit infochi mps / master





  • 仅合并

>

 
git read-tree --prefix = cassandra / -u infochimps / master:cookbooks / cassandra





  • 提交更改



 
git commit -m'在infochimps cassandra中合并'






附录



奇怪, [edit me] - 但读取树


$ b


错误:Entry'infochimps / cookbooks / cassandra / README'与'cookbooks / cassandra / README'重叠。无法绑定


...即使两个文件都是相同。这可能有助于:

  git rm -r cassandra 
git读取树--prefix = cassandra / -u infochimps / master:cookbooks / cassandra

但是,当然,请手动验证这是否符合您的要求。


Is it possible to merge only the changes for a sub-directory from a local git branch to a remote git branch or is it "all or nothing"?

For example, I have:

branch-a
 - content-1
 - dir-1
   - content-2

and

branch-b
 - content-1
 - dir-1
   - `content-2

I only want to merge the contents of branch-a dir-1 with the contents of branch-b dir-1.

解决方案

Just as an alternative to the SO question "How do you merge selective files with git-merge?", I just found this GitHub thread which could be more adapted for merging a whole subdirectory, based on git read-tree:

  • My repository => cookbooks
    My repository target directory => cookbooks/cassandra

  • Remote repository => infochimps
    Remote repository source I want merged into cookbooks/cassandra => infochimps/cookbooks/cassandra

Here are the commands I used to merge them

  • Add the repository and fetch it

git remote add -f infochimps git://github.com/infochimps/cluster_chef.git

  • Perform the merge

git merge -s ours --no-commit infochimps/master

  • Merge only infochimps/cookbooks/cassandra into cassandra

git read-tree --prefix=cassandra/ -u infochimps/master:cookbooks/cassandra

  • Commit the change

 git commit -m 'merging in infochimps cassandra'


Addendum

It's bizarre,[edit me] — but the read-tree step can possibly fail like this:

error: Entry 'infochimps/cookbooks/cassandra/README' overlaps with 'cookbooks/cassandra/README'. Cannot bind.

... even when both files are identical. This might help:

git rm -r cassandra
git read-tree --prefix=cassandra/ -u infochimps/master:cookbooks/cassandra

But off course, verify manually that this does what you want.

这篇关于如何合并git中的子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆