将一个远程存储库与另一个存储库进行同步,以确保两者之间无冲突,并且始终有一个特定的存储库来解决冲突

时间:2020-09-25 08:17:02

标签: git

我有一个开发团队使用的远程存储库(源)和一个用于devops的目标远程存储库(目标)。大多数更改是在源存储库上进行的,但也有一些更改是在目标存储库上进行的。我正在使用本地存储库来合并两个远程存储库,然后将合并的代码推送到devops(目标)存储库。

我需要的是

  1. 在所有冲突中都存在来自原始(开发团队)存储库的更改
  2. 保留目标(devops团队)存储库中可能存在的所有未合并更改

这些是我一直使用的git命令,确信我们的策略正在按预期合并冲突,但我注意到在最近的冲突中,从目标存储库中提取的内容占了上风。

-- Cloning the origin repository
git clone <origin-repo-url>

-- Checking out the wanted branch
git checkout <branch-name>

-- Adding the destination remote repository
git remote add <dest-repo> <dest-repo-url>

-- Fetching/merging code from the destination repository
git pull -X ours <dest-repo> <dest-branch-name> --allow-unrelated-histories

-- Pushing the merged code to the destination repository
git push --force --tags <dest-repo> <origin-branch-name>:<dest-branch-name>

0 个答案:

没有答案