为什么git不会尝试合并对重命名文件的更改? [英] Why doesn't git attempt to merge changes to renamed files?
问题描述
假设我有一个文件
- 在主文件中修改
- 分支
- 重命名为功能分支
当我尝试从主分支合并到功能分支,合并失败,带有
CONFLICT(修改/删除):X在HEAD中删除并在原点/主号中修改。
我知道存在冲突,但为何它甚至不尝试合并更改并在文件中放置冲突标记? 以前的答案似乎暗示它应该所有我得到的是两个不同版本的文件,我必须手动找出差异,并且端口从主版本一行一行地逐行更改为我的版本。
重现步骤:
git init
touch a
git add a
git commit -m'initial导入'
git checkout -b feature1
echo feature1> a
git添加
git commit -m feature1
git mv ab
git commit -m feature1
git checkout master
echo bugfix > a
git添加
git commit -m bug修正
git checkout feature1
git merge master
因为在git中实际上没有第一级重命名操作的概念,它只是使用文件的阈值检测重命名差异。
尝试合并:
git merge master -s recursive -X rename-threshold = 5%
Let's say I have a file that's
- Modified in master
- Modified in a feature branch
- Renamed in a feature branch
When I try to merge up from master to the feature branch, merge fails with
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.
Steps to reproduce:
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
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.
Try merging with:
git merge master -s recursive -X rename-threshold=5%
这篇关于为什么git不会尝试合并对重命名文件的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!