我可以从其他git存储库中仅抽取某些文件吗? [英] Can I pull only certain files from another git repository?

查看:65
本文介绍了我可以从其他git存储库中仅抽取某些文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,假设我有Repository 1和Repository 2. Repository 1有一个文件 / a / b / c / d 。我可以将这个文件导入到Repository 2中作为 / e / f / g / h



原因是我想从不同的git存储库的实验分支中引入更改。我尝试将所有的东西合并在一起,但是有很多冲突(各种各样)。因此,我怀疑我可以合并整个分支,但我想尽可能多地引入。



有什么办法可以做到吗?我想要做的,或者我只是不得不求助于直接复制文件?

解决方案

您可以从远程仓库使用 git archive 。然后,您可以添加文件并将其提交到您的存储库。这种方法不会保留他的分支的历史。有关详细信息,请参阅 git存档文档



如果您想尝试保留该实验分支的某些部分,可以使用 git fetch 他的存储库,然后 git rebase 他的实验分支到你的版本库中,根据需要编辑或跳过冲突提交。一旦您在存储库中清除了分支,可以将其合并。请参阅 git rebase docs


For instance, suppose I have Repository 1 and Repository 2. Repository 1 has a file /a/b/c/d. Would it be possible for me to import this file into Repository 2 as /e/f/g/h?

The reason being that I want to pull in changes from an experimental branch from a different git repository. I tried merging everything together, but there were a ton of conflicts (of every kind). Therefore, I doubt that I can merge the entire branch in, but I would like to try to bring in as much as I can.

Is there any way to do what I want to do, or am I just going to have to resort to copying files directly?

解决方案

You can get files from the remote repository using git archive. You could then add and commit the files to your repository. This approach will not preserve history from his branch. See git archive docs for details.

If you want to try to preserve parts of that experimental branch, you could git fetch his repository, and then git rebase his experimental branch onto your repository, editing or skipping commits with conflicts as appropriate. Once you have a cleaned up branch in your repository, you can merge that in. See git rebase docs

这篇关于我可以从其他git存储库中仅抽取某些文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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