为什么 git 不尝试合并对重命名文件的更改? [英] Why doesn't git attempt to merge changes to renamed files?

查看:17
本文介绍了为什么 git 不尝试合并对重命名文件的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个文件

  1. 在 master 中修改
  2. 在功能分支中修改
  3. 在功能分支中重命名

当我尝试从主分支合并到功能分支时,合并失败

When I try to merge up from master to the feature branch, merge fails with

CONFLICT(修改/删除):X 在 HEAD 中删除并在 origin/master 中修改.X 的版本来源/主版本留在树中.

CONFLICT (modify/delete): X deleted in HEAD and modified in origin/master. Version origin/master of X left in tree.

我知道存在冲突,但为什么它甚至不尝试合并更改并将冲突标记放在文件中?以前的答案似乎暗示应该这样做.所有我得到的是文件的两个不同版本,我必须手动找出差异并逐行从主版本到我的版本更改端口.

I understand that there is a conflict, but why doesn't it even try to merge changes and place conflict markers in the file? Previous answers seem to imply that it should. All I get is two different versions of the file, where I have to figure out the difference manually and port changes line by line from master version to my version.

重现步骤:

git init
touch a
git add a
git commit -m 'initial import'

git checkout -b feature1
echo feature1 > a
git add a
git commit -m feature1
git mv a b
git commit -m feature1

git checkout master
echo bugfix > a
git add a
git commit -m bugfix

git checkout feature1 
git merge master 

推荐答案

因为实际上 git 中没有一流的重命名操作的概念,它只是使用文件差异的阈值来检测"重命名.您的文件可能太不同了.

Because there is actually no concept of first-class rename operation in git, it just "detects" renames using a threshold for file differences. Your files are probably too different.

尝试合并:git merge master -s recursive -X rename-threshold=5%

这篇关于为什么 git 不尝试合并对重命名文件的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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