1

I am using Github and TeamCity. The line breaks of txt files don't exist after committing them to Github, what can I do in order to keep these line breaks in txt files?

When I am using notepad++ to view these files- the line-breaks appear, but when using Windows notepad there are no line breaks.

I googled for a solution and I found that if add a new file in the root directory .gitattributes that will contain:

*.txt crlf

tried also

*.txt eol=crlf

it will solve the problem, so I committed it to Github and then tried to download the txt file again, but it still don't show the line breaks.

What else can be done? how can I be certain that Github is using the .gitattributes that I added? cause it don't seem to use it.


To solve that issue I ended up adding .gitattributes file to the root folder of the project with this content:

# Windows-only files
*.txt text eol=crlf

But this only handle the problem in Github, I use Github and also TeamCity So when I downloaded the text file through TeamCity, the file EOL was not set to CRLF in TeamCity this checkbox need to be checked also (its in the VCS): enter image description here

E.Meir
  • 1,736
  • 4
  • 27
  • 48

1 Answers1

3

As I mentioned here, with Git 2.16 or more, you can do, on your local repo, where you have added or pulled the .gitattributes file:

git add --renormalize .
git commit -m "Introduce end-of-line normalization"

You can test it using the latest portable Git (like PortableGit-2.17.0-64-bit.7z.exe), and using a simplified PATH.

This is simpler than trying to do the same with TortoiseGit for now.


If everything still fails locally, some tool must change the file content, and that is what the OP has found: here, TeamCity didn't have the proper option selected.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • can i achieve it, using TortoiseGit? – E.Meir Apr 15 '18 at 15:05
  • @E.Meir No: if you are on Windows, just unciompress https://github.com/git-for-windows/git/releases/download/v2.17.0.windows.1/PortableGit-2.17.0-64-bit.7z.exe anywhere you want, add it to your PATH and you are good to go. No setup required. – VonC Apr 15 '18 at 15:06
  • yes. i am on windows- and then via CMD, enter the lines you suggested ? – E.Meir Apr 15 '18 at 15:08
  • @E.Meir yes, provided `git version` returns 2.16 or more, and that you are within your cloned repo folder. Then ush back to github. – VonC Apr 15 '18 at 15:09
  • I uncompressed it, what should i add to the Path variable? – E.Meir Apr 15 '18 at 15:10
  • @E.Meir Just for testing, you can enter what I mention in https://stackoverflow.com/a/47688159/6309: no need to modify your User environment variables just yet. – VonC Apr 15 '18 at 15:10
  • @E.Meir you should then push back To GitHub your new commit (check first with git log: you should see a new commit. – VonC Apr 16 '18 at 07:02
  • @E.Meir Can you give an example of a file with no newlines on your GitHub repo? – VonC Apr 16 '18 at 07:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169057/discussion-between-e-meir-and-vonc). – E.Meir Apr 16 '18 at 07:14
  • @E.Meir Good catch. I have updated the answer to reflect that possibility. – VonC Apr 16 '18 at 11:18