Git 树外文件的三向合并?

Git 树外文件的三向合并?,git,merge,Git,Merge,我们的代码库从不同的代码库导入文件,并修改它们以适应我们的代码库。出于实际原因(与问题无关),我们不能分享代码库的历史 如何执行导入文件的三向合并?其中: 公共祖先是源代码库以前导入的版本 分支1是源代码库的更新版本 分支2是我们的修改版本 我最好使用git来执行此合并,以避免依赖外部工具,但git与一个在本例中不存在的共享历史有着紧密的联系,我不知道如何强制git在只提供文件而不提供历史的情况下进行合并。您可以使用git merge file()逐个文件地执行此操作。如果涉及到很多文件,这

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

如何执行导入文件的三向合并?其中:

  • 公共祖先是源代码库以前导入的版本
  • 分支1是源代码库的更新版本
  • 分支2是我们的修改版本

我最好使用git来执行此合并,以避免依赖外部工具,但git与一个在本例中不存在的共享历史有着紧密的联系,我不知道如何强制git在只提供文件而不提供历史的情况下进行合并。

您可以使用
git merge file
()逐个文件地执行此操作。如果涉及到很多文件,这可能会非常乏味

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

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

后者可能有更多的移动部件,但我敢打赌你可以编写它们的脚本,而且它比逐个文件地执行单个
合并文件
命令要简单得多。

你可以使用
git merge file
()逐个文件地执行此操作。如果涉及到很多文件,这可能会非常乏味

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

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

后者可能有更多的移动部件,但我敢打赌你可以编写它们的脚本,这比逐个文件执行单个
合并文件
命令要简单得多。

谢谢!我不知道git合并文件。这确实是脚本化过程的一部分。非常好的建议:)谢谢!我不知道git合并文件。这确实是脚本化过程的一部分。很好的建议:)