Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Git show changes to my .sql files?

Tags:

I have tried adding this to the .gitattributes:

* text=auto *.sql diff 

But it still shows like this:

BIN  WebRole/Sql/Objects/dbo.Content.Table.sql → WebRole/Sql/dbo.Content.Table.sql Binary file not shown 

Would appreciate help with this.

like image 652
Samantha J T Star Avatar asked Jul 21 '15 13:07

Samantha J T Star


People also ask

Why does git think my .SQL file is a binary file?

gitattributes has a new working-tree-encoding attribute. As mentioned in "Set file as non-binary in git": "Why is Git marking my file as binary?" The answer is because it's seeing a NUL (0) byte somewhere within the first 8000 characters of the file.


1 Answers

The only method I found that worked was to change the encoding of .sql files from the default UTF16 encoding to UTF8. The below outlines three approaches based on your circumstances:

For a small number of files

  1. Within Visual Studio or SSMS choose Save As
  2. Choose the drop down arrow beside the save button enter image description here
  3. Choose "Save with encoding..."
  4. Select Yes to the Confirm Save As dialog

enter image description here

  1. Choose Unicode (UTF-8 with signature) - CodePage 65001 from the resulting dialog box and press OK. Note that the UTF-8 option is usually above the currently selected encoding (Unicode - Codepage 1200)

enter image description here

For a large number of files

If you have many files to change and are comfortable with running Powershell scripts you may want to try the following:

  1. Download the powershell script created by Microsoft MCC, MVP Stefan Roth from this link
  2. The powershell script is not digitally signed so you will need to open powershell as an administrator and then downgrade your execution policy (temporarily) outlined here. Choose either the bypass or unrestricted policy.
  3. How to run powershell scripts is detailed here. The path to the script will need quotes around it. The script then requires source and destination folders which must not be surrounded in quotes. The Encoding requested is simply utf8.

For any future files created

In order to prevent having to convert files in the future you can alter the template for the new queries created in SSMS by using the approach outlined in this link

like image 172
mrduncle1 Avatar answered Nov 01 '22 12:11

mrduncle1