如何将非快进git合并到未签出的分支? [英] How to do a non-fast-forward git merge to a branch that isn't checked out?

查看:63
本文介绍了如何将非快进git合并到未签出的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在分支a上.我想将分支b合并到分支c中.合并不是一个快速的过程,但是它也不需要手动解析. (即,这不是最简单的情况,但也不是最困难的情况,因此,这是Git能够在不需要人工的情况下自行完成的合并.)

I'm on branch a. I want to merge branch b into branch c. The merge is not a fast-forward, but it also doesn't require manual resolution. (i.e., it's not the simplest case, but it's also not the most difficult one, so it's a merge that Git is able to do on its own without needing a human.)

我是否可以通过这种方式将b合并到c,而不必签出任何分支?怎么样?

Is there a way for me to do this merge from b to c without having to check out any branch? How?

更新:如果您知道可以执行此操作的替代Git实现,那么这也是一个有效的解决方案.但是编写脚本以编程方式进行检出并不是一个好的解决方案,因为它仍然需要我拥有一个干净的工作目录.

UPDATE: If you know of an alternative Git implementation that can do it, that would be a valid solution as well. But writing a script that would do the checkouts programmatically would not be a good solution, because it would still require me to have a clean working directory.

推荐答案

如果合并不涉及两个分支上都涉及到的文件,那么我认为您希望git read-treegit write-tree具有边带GIT_INDEX_FILE.这应该做到:

If the merge doesn't involve files touched on both branches then I think you want git read-tree and git write-tree with a sideband GIT_INDEX_FILE. This should do it:

#!/bin/sh
export GIT_INDEX_FILE=.git/aux-merge-index
trap 'rm -f '"'$GIT_INDEX_FILE'" 0 1 2 3 15
set -e
git read-tree -im `git merge-base $2 $1` $2 $1
git write-tree \
| xargs -i@ git commit-tree @ -p $2 -p $1 -m "Merge $1 into $2" \
| xargs git update-ref -m"Merge $1 into $2" refs/heads/$2

您也可以使用git mktree </dev/null而不是merge-basebc视为完全不相关的分支,并使合并的结果合并每个文件,而不是将两个文件中缺失的文件都视为删除文件.

You could also use git mktree </dev/null instead of the merge-base to treat b and c as entirely unrelated branches and make the resulting merge combine the files in each rather than treating files missing in either as deletions.

您说您的合并不是一种快速的方法,因此您将需要阅读read-tree文档,以使上面的序列完全符合您的要求. --aggressive看起来可能是正确的,这取决于分支之间的实际差异是什么.

You say your merge isn't a fast-forward, so you're going to need to read the read-tree docs to make the sequence above do exactly what you want. --aggressive looks like it might be right, it depends on what the actual differences between your branches are.

编辑添加了空树库以处理无关树 编辑2 吊起我说过的或在评论中隐含的有效载荷

edit added the empty-tree base to handle unrelated trees edit 2 hoisting some payload I said or left implicit in a comment

这篇关于如何将非快进git合并到未签出的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆