且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Git交互式合并?

更新时间:2022-12-03 11:08:10

是的,但主要是通过手动实现。你会告诉Git你合并了两个相关的分支,但它不应该尝试单独提交结果,(编辑以添加:,如果它认为合并)
$ b $ pre $ g $ git merge --no-commit --no-ff分支合并

然后你会问这个文件,因为它出现在两个分支中:

  git show HEAD:filename> filename.HEAD 
git show分支合并:文件名>文件名.branch

及其合并基础,

  git show git merge-base HEAD branch-to-merge`:filename> filename.base 

你可以用你想要的任何工具合并它们(例如)。

$ $ $ $ $ $ $ meld filename {HEAD,branch,base}

您会将它放到( git add filename ) ,然后提交合并( git commit )。


I have two branches with the exact same file (incase you are wondering it is a .sql file) and I want to interactively merge it.

Pretty much I want to open up a diff program like I do when there is a conflict (or command line) and select exactly what lines go where.

Is there anyway to do this?

Yes, but it will mostly be by manually making that happen. You'll tell Git you're merging the two relevant branches, but that it shouldn't try to commit the result on its own, (edited to add: nor fast-forward if it thinks the merge is trivial):

git merge --no-commit --no-ff branch-to-merge

Then you'll ask git for the file as it appeared in the two branches:

git show HEAD:filename >filename.HEAD
git show branch-to-merge:filename >filename.branch

and their merge base,

git show `git merge-base HEAD branch-to-merge`:filename  >filename.base

You'll merge them using whatever tool you want (e.g.)

meld filename.{HEAD,branch,base}

you'll stage that (git add filename), and then commit the merge (git commit).