跨仓库依赖的最佳实践

3

以下是一个场景:

  • Repo A是一个庞大的代码库,有许多模块和依赖项。它不容易安装。它由其他人维护,并托管在Github上。
  • Repo A包含一个模块X,非常有用,几乎没有与Repo A其余部分的依赖关系
  • 我正在维护Repo B(托管在Github上),这是一个小型项目,希望使其易于分发。
  • 我想在Repo B中使用模块X的功能。

现在我可以将模块X复制到Repo B中以实现此目的。但如果Repo A的维护者对模块X进行了重要的错误修复,我就无法知道。我应该如何解决这个问题呢?

1个回答

1
假设模块X在RepoA的branchX中管理,您想在RepoB的master分支中使用模块X的功能,并想知道模块X在RepoA中是否有更新。因此,您可以将RepoA的远程添加到RepoB。详细步骤如下:

1.在RepoB的master分支中应用模块X(RepoA的branchX):

# In local RepoB
git remote add repoA <URL for RepoA>
git checkout master
git pull repoA branchX --allow-unrelated-histories

注意:如果有冲突,您需要修改并保存冲突文件,然后使用。
git add .
git commit

2. 检查RepoA中的branchX是否有更新:

git fetch repoA branchX 

If the output likes:

$ git fetch repoA branchX
From https://github.com/account/RepoA
 * branch            branchX          -> FETCH_HEAD

这意味着RepoA中的branchX(模块X)没有更新。
如果输出结果类似于:
$ git fetch repoA branchX
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/account/RepoA
 * branch            branchX          -> FETCH_HEAD
   65cd100..6abbf6c  branchX          -> repoA/branchX

这意味着在 RepoA 的 branchX(模块 X)中有更新。如果你想将 branchX 的更新应用到你的 master 分支上,可以使用以下方法:
git checkout master  #If your current branch is not master
git pull repoA branchX

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接