1

I created two branches, dev and feature.

Both of them contain the file conflict.txt and store different contents (the file is added and commited in each branch).

When I merge feature to dev branch, it conflicts as expected.

However, there are no hints inside the content of conflict.txt file as what normally happens when you have a conflict. It just contains the original content I edited on the dev branch without hints like:

<<<<<<< HEAD
issue1
=======
issue2
>>>>>>> issue2

Only one line plain text "issue1".

I ran the git diff command and it shows the conflict.txt is a binary file. But it's not, and I think that may be the problem.

diff --cc conflict.txt
index 2bc0433,ca61243..0000000
Binary files differ

How can I fix it?


  • OS: Windows11 22H2(Chinese Home Edition)
  • Git:2.37.1.windows.1
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
rpish
  • 31
  • 4

2 Answers2

1

It's showing you conflicting sets of change hunks. Since the file wasn't there at the merge base, then in each branch the change is the whole file.

That's not the kind of change the standard workflow automation is built for, its normal tradeoffs lead to the bad results you're dealing with, so you have to haul some tools off the rack and get in there yourself.

One way to do it is git checkout --patch :3:path/to/file. That will walk you through the differences between the two tips, one by one, it's digging in to the hunks for you.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • Thanks for give me so detailed help.I tried to change the base(the conflicted file is commited in the parent branch firstly) but it still not work.And it works well whether I changed the base or not in Ubuntu.I think it may be OS or CharacterSet problem coz I'm using Windows Chinese Edition. – rpish Jul 24 '22 at 03:03
1

Thanks jthill and dcat52 for giving me such useful help. I finally solved it.>﹏<

The problem is Windows Chinese Edition using UTF-16 as default Character Set not UTF-8. Git cannot treat UTF-16 encoded file as Text even if the postfix of the file is txt. The solution is change the OS character set to UTF-8. Detailed procedure is:

  • open Setting
  • Select Time and Language Option
  • Select the Manage Language Setting option under Related Setting (A new windows will pop-up)
  • Click Change System Region Setting(another new window will pop-up)
  • check Beta:Using Unicode UTF-8 for global language support and submit it

After reboot the OS,try again,everything works well.

rpish
  • 31
  • 4