`git merge -s theirs` 需要,但它不存在 [英] `git merge -s theirs` needed but it does not exist

查看:28
本文介绍了`git merge -s theirs` 需要,但它不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多要合并的远程存储库.这些存储库中的一些子树对于远程是唯一的(它们包含特定于主机的数据),其他子树包含(应该)在所有远程中通用的数据.

I have a number of remote repositories that I want to merge together. Some of the subtrees in those repositories are unique to the remote (they contain data that is host-specific), other subtrees contain data that is (supposed to be) common across all remotes.

本质上,我想做的是为每个遥控器运行git pull".这将沿着远程 master 的跟踪分支快进本地 master 分支,用于在远程已更改的主机特定文件,并且不会对公共文件执行任何操作,因为它们不会更改.

What I want to do, essentially, is run "git pull " for each remote. This will fast-forward the local master branch along the tracking branch for the remote master for host-specific files that have changed on the remote, and will do nothing for the common files because they will not have changed.

公共文件中的更改(称为 F,更改为 F')应该不是问题,即使它最初只发生在一个遥控器上.git-merge 会做正确的事,并在我的复合工作区中给我一个 F' 的副本,这正是我想要的.如果相同的公共文件在另一个遥控器上以不同的方式更改(称为 F"),问题就会出现.git-merge 会给我一个 F' 和 F" 的组合,这不是我想要的.我只想要 F".

A change in a common file (call it F, with the change being F') shouldn't be a problem, even if it only happens on one remote at first. git-merge will Do The Right Thing and give me a copy of F' in my composite workspace, which is what I want. The problem comes if the same common file changes in a different way on another remote (call it F"). git-merge will give me a composite of F' and F", which isn't what I want. All I want is F".

当我使用 ClearCase 时,我们称之为复制合并.合并的结果始终是贡献者的精确副本.这听起来很像git merge -s theirs",只不过它不存在.

When I worked with ClearCase we called this a copy-merge. The result of the merge was always an exact copy of the contributor. This sounds a lot like "git merge -s theirs" would be, except that it doesn't exist.

我想知道我是否可以用git-read-tree -m --trivial"来做些东西来让快进合并不碍事,然后用 git-merge 和一个自定义的合并工具来做一些魔术将 $REMOTE 文件复制到 $MERGED.但即便如此,如果合并是微不足道的,我也不知道如何阻止 git-merge 合成 F' 和 F".

I wondering whether I can cook something up with "git-read-tree -m --trivial" to get the fast-forward merges out of the way, then do some magic with git-merge and a custom mergetool that simply copies the $REMOTE file to $MERGED. But even with that I don't see how I can stop git-merge from compositing F' and F" if it things the merge is trivial.

我已阅读链接是否有他们的"?本网站上的git merge -s ours"版本?,以及 Junio Hamano 的帖子,它引用了解释为什么git merge -s theirs"是如此糟糕的主意,但情况并非如此我.我确实重视旧的历史,但我需要跳槽并在发生变化时跟踪远程站点上的变化.本地站点上没有完成任何新工作.它只需要形成所有远程站点的组合,当一个远程站点发生变化时,从最后一个轮询的远程站点中获取最新的公共"文件.

I've read the link Is there a "theirs" version of "git merge -s ours"? on this site, and the post by Junio Hamano it references explaining why "git merge -s theirs" is such a bad idea, but this isn't the case for me. I do value the old history, but I need to jump ship and follow the change on the remote site when one happens. No new work is done on the local site. It simply needs to form a composite of all the remote sites, taking the latest "common" file from the last polled remote when one changes.

预先感谢您能给我的任何帮助.

Thanks in advance for any help you can give me.

推荐答案

非常感谢 @VonC 建议在 中使用 merge=custom-driver 属性.gitattributes 文件.虽然这行得通,但我不愿意用 .git 文件污染我的工作区,虽然我可以使用 $GIT_DIR/info/attributes 来避免污染,但我我对捕获点文件和非点文件需要 2 条规则感到困扰.

Many thanks to @VonC for suggesting the use of the merge=custom-driver attribute in the .gitattributes file. While this will work, I'm reluctant to pollute my workspace with .git files, and while I could use $GIT_DIR/info/attributes to avoid the pollution, I'm bothered by the need for 2 rules to catch dot-files and non-dot files.

经过一些实验,我设法获得了一个解决方案,merge.default 配置变量(在 gitattributes(5) 手册页中提到)工作.我错过的技巧是 merge.default 使用您之前定义的自定义驱动程序的名称;你没有直接给它自定义命令.这对我有用...

After a bit of experimentation I managed to get a solution with the merge.default configuration variable (mentioned in the gitattributes(5) manpage) working. The trick I missed was that merge.default takes the name of a custom driver you have defined previously; you don't give it the custom command directly. Here's what works for me...

首先定义您的复制合并自定义驱动程序.可以直接使用shell命令;不需要外部脚本(只需确保正确引用 shell 元字符即可):

First define your copy-merge custom driver. You can use shell commands directly; there's no need for an external script (just make sure you get your shell meta-character quoting right):

git config merge.copy-merge.name   'Copy Merge'
git config merge.copy-merge.driver 'mv %B %A'

请注意,mv 成功返回 0,失败返回 1,符合将合并成功"报告回 git 的标准.

Note that mv returns 0 on success, 1 on failure, meeting the criteria for reporting merge "success" back to git.

现在告诉 git 所有合并都是复制合并:

Now tell git that ALL merges are copy-merges:

git config merge.default copy-merge

嘿,Presto!任务完成.git merge 现在将复制合并所有内容,以便您所在的分支包含 上所有文件的精确副本.QED.

Hey Presto! Job done. git merge <branch> will now copy-merge everything so the branch you're on contains exact copies of all files on <branch>. QED.

如果您想进行非复制合并,只需重置默认合并驱动程序:

If you want to do a non-copy-merge then simply reset the default merge driver:

git config --unset merge.default

如果您确实想要更有选择性,那么请不要设置 merge.default 并使用 @VonC 所说的属性:

If you do want to be more selective then leave merge.default unset and use attributes as @VonC says:

cd path/to/copy-merge/in
echo '* merge=copy-merge'  >  .gitattributes
echo '.* merge=copy-merge' >> .gitattributes

在您想要复制合并的每个子树的顶部执行此操作.如果有您不想复制合并的子子树,您可以再次将其关闭:

Do this at the top of every subtree you want to copy-merge in. If there's a sub-subtree that you DON'T want to copy-merge in, you can turn it off again:

cd path/to/copy-merge/in/path/to/normal-merge/in
echo '* merge'  >  .gitattributes
echo '.* merge' >> .gitattributes

警告:用大量 .gitattributes 文件乱扔你的工作树肯定会导致混乱,特别是如果你还在其他目录中使用诸如*.bin -merge"之类的东西来强制所有 .bin 文件合并失败冲突.最好将 $GIT_DIR/info/attributes 用于此类事情,因为它具有最高优先级.

WARNING: littering your working tree with lots of .gitattributes files is bound to lead to confusion, especially if you also use things like "*.bin -merge" in other directories to force all merges of .bin files to fail with conflicts. It may be better to use $GIT_DIR/info/attributes for this sort of thing, as it has the highest precedence.

这篇关于`git merge -s theirs` 需要,但它不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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