1

This has happened twice. The first time to 4 or 5 files. The second time to just one, but I was only pushing one at the time. I am using Visual Studio 2013 to edit PowerShell scripts. I don't know if this is relevant as I think they are just UTF-8 files when Git deals with them. I'm not sure if it's at the time of commit or push but my files are getting messed up. An example of the first few lines when it's clean:

$Start=Get-Date
$Global:Timings=@()
$Global:Timings+=1
#$Global:Timings+=2
function Stamp($msg){ $Global:Timings += @{Date=(Get-Date).addseconds(4);Message=$msg} }

I pushed that at work and when I got home and pulled it, I get: http://pastebin.com/EgVzZZHs

The new file is full of when I am thinking are Chinese characters. I had to use pastebin because superuser doesn't allow those characters. According to some file analysis, the original is UTF-8 while the new file is UTF-16 Big Endian. The file looks similarly messed up in Notepad, SciTe, Visual Studio, WinMerge, and the tools in Tortoise Git. I suspect (based on my recollection of the last time this happened) but can't verify at the moment, that the file on my disk at work will be fine. I don't know if Git's index will be messed up, but I think if I pull, the good file will get replaced with the bad file. Both clients are Windows 7. The remote repo is on BitBucket. It's only a week or so old. Does anyone have any idea what's happening and/or how to prevent it? I'm super bummed out about this. Many thanks!

1 Answer 1

1

I realize this is an old question, but this came up first on Google for me.

You are correct that the problem is that the file encoding is something other than UTF-8. However I think that encoding switch happened before you pushed to Bitbucket. You can fix this with Sublime Text or Notepad++ easily, if you have an uncorrupted copy of the file. Just open the offending file up in Sublime Text, paste in the correct code and then use the File->Save With Encoding->UTF-8 command. Then push it back up to Bitbucket. I also noticed that the file displayed correctly on the Bitbucket interface even though it would get messed up after being pulled. So you might be able to copy the code directly out of the Bitbucket interface.

https://stackoverflow.com/questions/17515768/git-messed-up-my-files-showing-chinese-characters-in-some-places

https://stackoverflow.com/questions/21289157/set-encoding-of-file-to-utf8-with-bom-in-sublime-text-3

1
  • Thankfully, this issue has become very rare for me. I think my .gitattributes and .git\config files are what are working at the moment. * -text and [core] autocrlf = false respectively The problem really seemed to be git modifying the line endings of the file when I didn't want or need it to. I haven't looked at it in a while. Oct 21, 2017 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .