[英]How to deal with xxx~HEAD after git merge?
In my branchA: 在我的分支A:
I copy a file from folder04/config.xml
to folder05/config.xml
, then git add
and commit
. 我将文件夹从folder04/config.xml
复制到folder05/config.xml
,然后git add
和commit
。
In my branchB (B is branch out from A): 在我的branchB中(B从A分支出来):
I already have one file named folder05/config.xml
. 我已经有一个名为folder05/config.xml
文件。
Now I merge branchA
into branchB
, it appears a weird conflict like this. 现在我将branchA
合并到branchB
,看起来像这样一个奇怪的冲突。
Untracked files: (use "git add <file>..." to include in what will be
committed)
folder05/config.xml~HEAD
It generates a file named config.xml~ HEAD , what does it means? 它生成一个名为config.xml~ HEAD的文件,这意味着什么?
I can't understand why, and what should I do in this situation? 我无法理解为什么,在这种情况下我该怎么办?
It generates a file named config.xml~HEAD, what does it means? 它生成一个名为config.xml~HEAD的文件,这意味着什么?
This file was generated automatically by git
because you had a filename collision conflict - you had two items that were unrelated in the two branches trying to occupy the name config.xml
. 这个文件是由git
自动生成的,因为你有一个文件夹冲突冲突 - 你有两个在试图占用名称config.xml
分支中无关的项目。
This could be caused by a variety of situations: 这可能是由各种情况造成的:
Most likely , you created file named config.xml
in your branch. 最有可能的是 ,您在分支中创建了名为config.xml
文件。 In the branch you're merging in, a different file was renamed to config.xml
. 在您要合并的分支中,将另一个文件重命名为 config.xml
。 Since these two files lack any common ancestor, they can't be merged. 由于这两个文件缺少任何共同的祖先,因此无法合并。 They should both be kept in the working directory, but as a conflict. 它们都应该保存在工作目录中,但是存在冲突。 So they will both be kept, but with unique names. 因此,他们都将被保留,但唯一的名称。
The config.xml
in the branch being merged will be checked out on disk as config.xml
. 正在合并的分支中的config.xml
将作为config.xml
在磁盘上检出。 The config.xml
in your branch will be checked out on disk as config.xml~HEAD
. 分支中的config.xml
将作为config.xml~HEAD
在磁盘上检出。
Here's an example, where we add a file named newname.txt
in our master
branch, and rename file.txt
into newname.txt
in the branch that we're merging in. In this case, a conflict will be raised and our branch's contents will be written as newname.txt~HEAD
in the working folder: 这是一个例子,我们在master
分支中添加一个名为newname.txt
的文件,并将file.txt
重命名为我们合并的分支中的newname.txt
。在这种情况下,将引发冲突并且我们分支的内容将在工作文件夹中写为newname.txt~HEAD
:
% git checkout -bbranch
Switched to a new branch 'branch'
% git mv file.txt newname.txt
% git commit -m"rename file -> newname"
[branch d37e379] rename file -> newname
1 file changed, 0 insertions(+), 0 deletions(-)
rename file.txt => newname.txt (100%)
% git checkout master
Switched to branch 'master'
% echo "new file" > newname.txt
% git add newname.txt
% git commit -m"added newname in master"
[master f7bd593] added newname in master
1 file changed, 1 insertion(+)
create mode 100644 newname.txt
% git merge branch
CONFLICT (rename/add): Rename file.txt->newname.txt in branch. newname.txt added in HEAD
Adding as newname.txt~HEAD instead
Automatic merge failed; fix conflicts and then commit the result.
Once you have resolved the conflict to your satisfaction and committed the merge, you can simply delete the ~HEAD
file from your working directory. 一旦您完全解决了冲突并提交了合并,您只需从工作目录中删除~HEAD
文件即可。
(Finally, remember that git does not track that renames occurred, it uses heuristics to detect renames. So this conflict - in practice - may not really be a conflict because the files may not have really been renamed.) (最后,请记住,git不跟踪发生的重命名,它使用启发式方法来检测重命名。所以这种冲突 - 实际上 - 可能不是真正的冲突,因为文件可能没有真正重命名。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.