如何从远程存储库合并/拉取

发布于 2024-10-24 17:09:50 字数 602 浏览 1 评论 0 原文

我正在尝试将远程 git 存储库中的一些子目录合并到我的存储库中。远程和本地存储库都包含整个内核存储库,我只对无线相关文件感兴趣。 我尝试按照 "How 下的说明进行操作使用子树合并策略”,但由于大多数文件同时存在于本地存储库和远程存储库中 git read-tree --prefix=dir-B/ -u Bproject/master 命令失败。我无法在同一命令行中使用 -m 选项和 --prefix

此合并实际上应该根据远程存储库中的文件更新(合并/拉取)所有相关的无线目录/文件,其中应通过优先选择远程文件来解决冲突。

为了使我的问题更笼统——假设您有存储库 A 和 B。两者都有文件夹 wireless_dir:A/wireless_dir、B/wireless_dir。我正在处理存储库 B,并希望从 A/wireless_dir 更新 B/wireless_dir 中的所有文件,其中发生合并冲突时首选 A/wireless_dir 中的更改。

I'm trying to merge a few subdirectories from a remote git repository to my repository. Both Remote and Local Repositories include the whole kernel repository and I'm interested only in the wireless relevant files.
I tried to follow the instructions under "How to use the subtree merge strategy", but since most of the files exist both in local repository and in remote repository the
git read-tree --prefix=dir-B/ -u Bproject/master command fails. I could not use -m option and --prefix in the same command line.

This merge actually should update (merge/pull) all relevant wireless directories/files according to the files in the remote repository where conflicts should be solve by preferring the remote files.

To make my question general -- say you have repository A and B. both have the folder wireless_dir: A/wireless_dir, B/wireless_dir. I'm working on repository B and would like to update all its files in B/wireless_dir from A/wireless_dir where changes in A/wireless_dir are preferred when merge conflicts occur.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念 2024-10-31 17:09:50

从 Jeformi 的评论来看,您似乎已经遇到了该文件夹是一个单独的存储库的情况,如果是这种情况,您只需执行 git pull 即可。

但是,如果您要查找的提交包含您不想要的其他文件夹中的文件,Git 允许您以圆形方式“取消”提交,如下所述:redhatmagazine

执行此操作的步骤(更适合您的情况)是:

1)记下您的 HEAD 当前所在的提交,为了好玩,我们将其称为 。这可以从日志中获取,并通过使用以下命令查看最近提交的 sha1:

git log

2) 将更改从存储库 A 拉入您的分支(这将包括您可能不想要的任何内容):

git pull <repo A> <branch_name>

3) 现在是时候使用 < code>(以非粗俗的方式)...这是通过重置完成的

git reset --mixed <OLD_HEAD>

4) 完成所有操作后,HEAD 又回到了 < /code> 和您的索引也是如此,但在您的工作目录中,您现在拥有您一直在寻找的存储库 A 中的更改,以及 wireless_dir 文件夹之外的文件的潜力。要以交互方式将工作目录中的这些文件合并到索引中(如果您想要的话,仅适用于 wireless_dir 中的文件):

git add --patch <filename>

5) 最后:

git commit -m “Selectively merged my files”

注意:如果您不想搞砸分支,请创建一个新分支在尝试上述操作之前先分支。

From what Jeformi commented, it appears you already have the situation where the folder is a separate repository, which if that's the case all you have to do is a git pull.

However, if the commits you're looking for have files from other folders that you don't want, Git allows you to "unsqaush" commits in a round about way as mentioned here: redhatmagazine

The steps to do this (a bit more generalized to your situation) are:

1) Make note of the commit your HEAD is currently at, let's call it <OLD_HEAD> for fun. This can be obtained from the log and looking at the most recent commit's sha1 by using:

git log

2) Pull in the changes from repo A into your branch (this will include any that you might not want):

git pull <repo A> <branch_name>

3) Now's it's time to use <OLD_HEAD> (in a non-vulgar way)... this is done by a reset

git reset --mixed <OLD_HEAD>

4) With everything you've done you're HEAD is back at <OLD_HEAD> and your index is as well, but in your working directory you now have the changes from repo A that you've been looking for, as well as the potential for files outside of the wireless_dir folder. To interactively merge these files in your working directory into your index use (only on the files from wireless_dir if that's all you want):

git add --patch <filename>

5) And finally:

git commit -m “Selectively merged my files”

Note: If you don't want to chance screwing up your branch, make a new branch before trying the above.

通知家属抬走 2024-10-31 17:09:50

最简单的方法是合并整个分支,将该文件夹复制到 git 树之外,撤消或中止合并,然后将文件夹复制回来。

但是,如果任何更改发生,您将会遇到问题该文件夹之外的依赖项。您可能想要cherry-pick涉及该文件夹的任何内容的整个提交(来自git log subdir)以提取依赖项。

The easiest way to do it is to merge the entire branch, copy that folder outside of your git tree, undo or abort the merge, then copy the folder back in.

However, you're going to have problems if any of the changes have dependencies outside that folder. You probably want to cherry-pick the entire commits of anything that touches that folder (from git log subdir) to pull in the dependencies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文