git - git merge-file 将整个文件标记为不同而不是部分
问题描述
我正在尝试在很久以前逐个文件分歧的git merge-file
两个分支(current
和)之间进行 3 路合并。other
我之所以选择这种方法,是因为这样做git merge
会导致太多的冲突并使其成为一场噩梦,而在一个文件基础上进行操作不会破坏所有内容,并且随着更改的进行更新所有测试会更容易。
然后的想法是使用这个脚本,它接受一个分支名称、一个文件名,并使用当前分支上文件的最后一个版本、分歧点的版本和另一个分支上最后一次提交的版本执行合并.
问题是,这个命令不是只突出显示不同的部分,而是简单地说整个文件有分歧,即使实际上只有几行不同。我在这里做错了什么?
#!/bin/bash
common_sha=$(git merge-base HEAD $1)
git show $common_sha:$2 > common
git show $1:$2 > theirs
git merge-file --diff3 $2 common theirs
rm common
rm theirs
这是正在使用的脚本的示例:
$ git branch -a
* current_branch
master
other_branch
$ my_merge.sh other_branch file.txt
这是它使用的文件
common version of file.txt
line 1
line 2
line 3
line 4
line 5
current branch's version of file.txt
line 1
line 2.2
line 3
line 4.1
line 6
other branch's version of file.txt
line 1
line 2.1
line 2.2
line 3
line 4
line 5
以及预期与实际结果
expected result after running the script
line 1
<<<<<<< file.txt
line 2.2
||||||| common
line 2
=======
line 2.1
line 2.2
>>>>>>> theirs
line 3
line 4.1
line 6
actual result
<<<<<<< file.txt
line 1
line 2.2
line 3
line 4.1
line 6
||||||| common
line 1
line 2
line 3
line 4
line 5
=======
line 1
line 2.1
line 2.2
line 3
line 4
line 5
>>>>>>> theirs
解决方案
检查文件:
git show HEAD:a-file > a.txt
git show $1:a-file > b.txt # replace $1 for the revision you are playing with
git show $( git merge-base HEAD $1 ):a-file > c.txt
在它们file a.txt b.txt c.txt
(可以告诉你格式(unix/windows)。如果它们混合在一起,这就是您看到该问题的原因。
推荐阅读
- uicollectionview - UICollectionViewCompositionalLayout 更新单元格高度
- python - NaN 值试图过滤熊猫数据框中的行
- reactjs - redux 状态在导航或浏览器后退按钮后恢复到以前的状态
- c# - Unity 3D:如何使用电影机制作边界?
- vue.js - vue v-for 性能问题
- php - 尝试在 Laravel 中实现模型时,在 Laravel 7.27.0 中找不到类“App\Newuser”
- r - 为什么 poly 中缺少多项式多元回归系数?
- python - 三元组的python累积总和?
- gradle - 我找不到 Gradle 任务的声明
- markdown - Markdown 是否可以选择横向放置列表?