如何使Git始终使用“他们/我们的"在重新设置基准期间解决特定文件中的冲突的方法? [英] How do I make Git always use "theirs/ours" for resolving conflicts in a particular file, during rebase?

查看:92
本文介绍了如何使Git始终使用“他们/我们的"在重新设置基准期间解决特定文件中的冲突的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从一个非常活跃的存储库中创建了自己的dev分支.该存储库(Clappr)还包含一个经过编译和缩小的文件,该文件会用源代码进行更新.

I've created my own dev branch from a pretty active repository. This repository (Clappr) also contains a compiled and minified file, which is updated with the source code.

每当我想用masterdev分支建立基础时,此文件就会发生冲突,因为它无法自动合并-当然,因为它是一个缩小的JS文件:

Whenever I want to rebase my dev branch with the master, this file is conflicting, because it cannot be automatically merged—of course, because it's a minified JS file:

$ git checkout dev
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: dummy commit
Using index info to reconstruct a base tree...
M   dist/clappr.js
M   src/playbacks/hls/hls.js
Falling back to patching base and 3-way merge...
Auto-merging src/playbacks/hls/hls.js
Auto-merging dist/clappr.js
CONFLICT (content): Merge conflict in dist/clappr.js

我可以使用--ours解决此冲突,但是对于尚未重新定标的master上的每个提交,我都必须这样做.

I can resolve this conflict using --ours, but I have to do this for every single commit on master that I haven't rebased yet.

我知道我可以完全跳过补丁,但是我可以以某种方式自动告诉Git忽略clappr.js文件,而总是使用我的dev分支中的任何内容吗?

I know I can skip a patch entirely, but can I somehow automatically tell Git to ignore that clappr.js file and just always use whatever is in my dev branch?

推荐答案

您可以定义自定义合并驱动程序(如"

You can define a custom merge driver (as in "Git: How to rebase many branches (with the same base commit) at once?" for a concrete example).

该合并驱动程序"keepMine"与dist/clappr.js关联,并在每个分支的.gitattributes文件中声明该合并驱动程序.
参见"

That merge driver "keepMine" associated with dist/clappr.js, and declare that merge driver in a .gitattributes file present in each of your branches.
See "How do I tell git to always select my local version for conflicted merges on a specific file?".

echo clappr.js merge=keepMine > dist/.gitattributes
git config merge.keepMine.name "always keep mine during merge"
git config merge.keepMine.driver "keepMine.sh %O %A %B"

keepMine.sh放置在$PATH中的某个位置,而不是在存储库中:

With keepMine.sh put somewhere in your $PATH, not in the repository:

# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0

(有关KeepTheir.sh,请参见"如何停止合并(再次…)")

(For a KeepTheir.sh, see "How to stop a merge (yet again…)")

更简单,如 branch14 所述. Questions/31560274/如何让git总是使用他们的解决冲突的方法/31560423#comment112422725_31560423>评论:

Linux已经有一个命令,该命令不能成功执行任何操作,恰当地命名为"true".

git config merge.keepMine.driver "true"

这篇关于如何使Git始终使用“他们/我们的"在重新设置基准期间解决特定文件中的冲突的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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