问题
In my branchA:
I copy a file from folder04/config.xml
to folder05/config.xml
, then git add
and commit
.
In my branchB (B is branch out from A):
I already have one file named folder05/config.xml
.
Now I merge branchA
into branchB
, it appears a weird conflict like this.
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?
I can't understand why, and what should I do in this situation?
回答1:
It generates a file named config.xml~HEAD, what does it means?
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
.
This could be caused by a variety of situations:
Most likely, you created file named config.xml
in your branch. In the branch you're merging in, a different file was renamed to 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
. The config.xml
in your branch will be checked out on disk as 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:
% 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.
(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.)
来源:https://stackoverflow.com/questions/48204077/how-to-deal-with-xxxhead-after-git-merge