How to: Change File Encoding?
While merging or comparing files using the DiffMerge tool, and files have different encoding, you will see this message:
"The character encodings on these files are different. Only files with the same character encoding can be merged or compared."
If you look at the properties window of a file in the Source Control Explorer or run tf prop itemSpec, you will see the encoding of the file as stored on the server the last time the encoding was set either explicitly using the /type argument during tf add or tf checkout, or implicitly when TFS tried its best effort to detect the file's encoding during the add operation. This encoding stored on the server may not match the latest version’s physical encoding, as someone could have checked-in the file in a different encoding or explicitly changed the encoding stored on the server. To solve this issue, you can detect the encoding using the properties dialog or set it to match the file’s physical encoding if you know it. The other thing that I can think of is that the encoding of the local files that we are trying to merge has been changed by a tool or an IDE. Open both files (source and target) in Source Control Explorer, detect and save their encoding, open the target file locally using Visual Studio and Save As With Encoding to make it match the merge source encoding.
Comments
- Anonymous
July 06, 2012
Yay--setting the encoding by saving with advanced options worked! Now when I try to compare, in addition to still getting the "character encodings are different" message (even though I set the same encoding), it also says, "Do you want Visual Studio to treat the files as having the same encoding?" When I click yes, it does the compare.