首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >树外文件的3种方式合并?

树外文件的3种方式合并?
EN

Stack Overflow用户
提问于 2017-10-25 19:58:34
回答 1查看 65关注 0票数 0

我们的代码库从不同的代码基导入文件,并修改它们以适应我们的代码基。我们不能分享代码库的历史,因为实际的原因(这与问题无关)。

如何对导入的文件执行3路合并?其中:

  • 共同祖先是源代码库以前导入的版本
  • 分支1是源代码库的更新版本
  • 第二分部是我们修改的版本。

我最好使用git来执行这个合并,以避免依赖于外部工具,但是git与在本例中不存在的共享历史紧密联系在一起,而且我不知道如何强制git进行合并,只考虑到文件而没有历史记录。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-25 20:23:40

您可以使用git merge-file (https://git-scm.com/docs/git-merge-file)逐个文件进行此操作。如果有许多文件涉及,这可能是相当乏味的。

或者,您可以创建临时的“集成repos”,在其中进行合并。

代码语言:javascript
复制
mkdir merge-repo
cd merge-repo
git init
# copy in the previous imported version of each file 
git add .
git commit -m base
git branch source
# copy in the current version of each file with your changes (note you're still on master)
git add .
git commit -m ours
git checkout source
# copy in the current version of each file from the source repo
git add .
git commit -m theirs
git checkout master
git merge source
# copy the merged files back to your repo
cd ..
rm -rf merge-repo #if you don't want to keep it around, you don't need it any more

后者可能有更多可移动的部分,但我敢打赌,您可以编写它们的脚本,这将比逐个文件处理单个merge-file命令要简单得多。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46941082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档