我们的代码库从不同的代码基导入文件,并修改它们以适应我们的代码基。我们不能分享代码库的历史,因为实际的原因(这与问题无关)。
如何对导入的文件执行3路合并?其中:
我最好使用git来执行这个合并,以避免依赖于外部工具,但是git与在本例中不存在的共享历史紧密联系在一起,而且我不知道如何强制git进行合并,只考虑到文件而没有历史记录。
发布于 2017-10-25 20:23:40
您可以使用git merge-file (https://git-scm.com/docs/git-merge-file)逐个文件进行此操作。如果有许多文件涉及,这可能是相当乏味的。
或者,您可以创建临时的“集成repos”,在其中进行合并。
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命令要简单得多。
https://stackoverflow.com/questions/46941082
复制相似问题