Arne Lund
Arne Lund

Reputation: 2456

How to fix windows line endings after git clone

I have cloned a repository from github on a Windows 7 box, and made some of changes I would hate to lose. However, all my file have wrong line endings, \n instead of \r\n.

How should I fix it?

I think I should clone my repo again with correct line endings, and move over my changes manually.

How do I clone it properly, so that all line ending are \r\n?

Are there any better suggestions?

Upvotes: 2

Views: 8572

Answers (2)

Noah
Noah

Reputation: 15340

Another way is to run the dos2unix win32 utility found here.

Info: dos2unix.exe converts MS-DOS text files to Unix format, by stripping any CR or end-of-file (Ctrl-Z) characters from the data.

Upvotes: 1

Andy
Andy

Reputation: 46534

You can't clone the repository with a different style of line endings. The data in the repository is what it is. What you can do is tell git how you want to handle the line endings when checking in or out. The link that birryree pointed out in the comments is a good source. There is also Github's help page on it.

Depending on what you are editing, you can also use a Windows text editor that doesn't require crlf, like notepad++. You can change the line endings that notepad++ uses by default in settings->preferences->New Document/Default Directory

To add from Charles' comment, you can also convert line endings to unix or windows style in notepad++. You do this by going to edit->EOL Conversion

Upvotes: 4

Related Questions