Could you please help me to understand this behavior:
On branch develop I have a file with two commits:
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (develop)
$ git log --oneline -- coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
8509cdf Added route generator based on freemarker template
1e890b7 Added XML configuration for test objects in StaticDataInitializer
Then I can switch to my feature branch:
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (develop)
$ git checkout feature/ZAA_tools_xmlgenerator
Switched to branch 'feature/ZAA_tools_xmlgenerator'
Your branch is up-to-date with 'origin/feature/ZAA_tools_xmlgenerator'.
And check that I have not commits for that file:
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (feature/ZAA_tools_xmlgenerator)
$ git log --oneline -- coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
That file does not exist in working directory either:
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (feature/ZAA_tools_xmlgenerator)
$ cat coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
cat: coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java: No such file or directory
But when I try to merge develop into my feature branch:
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (feature/ZAA_tools_xmlgenerator)
$ git merge develop
[...]
Auto-merging coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
CONFLICT (content): Merge conflict in coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
[...]
Automatic merge failed; fix conflicts and then commit the result.
And I get merge conflicts (both modified).
BOCZA2@PC45819 MINGW64 /c/nttcloud/gitlab/coba/ZAA (feature/ZAA_tools_xmlgenerator|MERGING)
$ git status -s coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
UU coba.zaa.model/coba.zaa.model.config/src/main/java/com/zaa/model/config/Channel.java
What is the problem? The file doesn't exist in the feature branch! What is the reason for the merge conflict? Is my repository corrupt? How can I find out the reason?
In my case I had this same issue because of the fact that file-renames in git are a run-time heuristic. (This is what Michael Monteith's answer proposes, but without a solution.)
git, at merge time, decided that the non-existing file in my branch was actually a rename of a file that does exist on my branch. Any files with 50% similarity in a single commit are considered a rename during the merge, by default. Asking git to merge with a higher threshold does the trick:
git merge master -X rename-threshold=100%
As to why I hit this issue: it's because our team decided on a single-squash-commit strategy for pull-requests. That means that individual commits on master are huge , thus multiplying the chance for "renames" within those single, massive commits.
It could be that the modified file in your feature branch has been renamed in the develop branch?
I had a problem where master had renamed a file for example A.java to B.java, and the feature branch had made changes to A.java.
I had merge conflicts with B.java even though the feature branch had no history of a file called B.java
我通过运行git reset
解决了这个问题。
First of all you can check.
// List git-ignored files
$ git ls-files . --ignored --exclude-standard --others
// List untracked files
$ git ls-files . --exclude-standard --others
and you can try.
1) "" git add . "" needs u to be in the correct directory, so you can try "" git add -A "" to add everything.
AND
2) git clean -f
In my case (IntelliJ IDEA) he had problems with one file mentioned in the Event Log. Since this file does not exist neither on both branches, I created an empty file with the conflicting name, committed and could merge again.
I did see the file also with git diff
I find that this happens whenever we change something about our css and js compiler/compressor code/engine/whatever. Generally just creating the files that it says have a conflict, yet don't exist mitigates the problem. It lets you commit the other files... but the problematic files still aren't committed. Then you can commit those files in a separate commit and then delete them and commit again and it's all fixed. Dumb crazy fix but it works every time.
If you are having difficulty identifying the conflict files I highly suggest the following.
First create a nice clean alias using this command
git config --global alias.conflicts "diff --name-only --diff-filter=U"
Then you can run
git conflicts
to easily get a list of the files that have an issue.
I had a similar issue after renaming a file and trying a rebase. I got the message:
"com.mycompany.fileThatDoesNotExist.java needs merge. You must edit all merge conflicts and then mark them as resolved using git add".
I solved it by removing the file with the command:
git rm com.mycompany.fileThatDoesNotExist.java
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.