git - CRLF issue in windows + linux dual boot
you are talking about text=auto part? I wasn't sure If I need to include that in a new
.gitattributes
file or not, because when I did, ATOM still showed the files as modified.
Yes, it does.
To force Git to apply .gitattributes
directives, see "Dealing with line endings".
I would first make sure core.autocrlf
is set to false.
git config --global core.autocrlf false
Then:
git add . -u
git commit -m "Saving files before refreshing line endings"
rm .git/index
git reset
git status
git add -u
git add .gitattributes
git commit -m "Normalize all the line endings"
You can also use, to force the index re-normalization:
git rm --cached -r .
git reset --hard
See "Force LF eol in git repo and working copy"
* text=auto eol=lf
git - dual boot ubuntu and windows with separate data partition
Your problem is that when you check out files on Windows with the git default config, they are created with CRLF
(the windows default) line endings in your working directory, but committed as LF
for cross-platform compatibility.
Now your Linux sees the CRLF
on every line and says that it’s different to the LF
in the repo. That’s why every line is reported as different.
I would suggest setting the line endings to LF
on windows. In a previous answer I explained the details of how to do that. Following those steps will also enable line-ending normalization to LF
on linux, which will avoid problems if you accidentally create some CRLF
on windows and commit that in linux later on.
You can also just disable line ending normalization completely, but that is likely to cause trouble in the future, unless you only use a completely fixed set of editors, whose line ending handling you know very will.
Git - Windows AND linux line-endings
On Windows:
$ git config --global core.autocrlf true
On Linux:
$ git config --global core.autocrlf input
Read more about Dealing with line endings
What's the strategy for handling CRLF (carriage return, line feed) with Git?
Almost four years after asking this question, I have finally
found an answer that completely satisfies me!
See the details in github:help's guide to
Dealing with line endings.
Git allows you to set the line ending properties for a
repo directly using the text attribute in the
.gitattributes
file. This file is committed into
the repo and overrides thecore.autocrlf
setting,
allowing you to ensure consistent behaviour for all
users regardless of their git settings.
And thus
The advantage of this is that your end of line
configuration now travels with your repository and you
don't need to worry about whether or not collaborators
have the proper global settings.
Here's an example of a .gitattributes
file
# Auto detect text files and perform LF normalization
* text=auto
*.cs text diff=csharp
*.java text diff=java
*.html text diff=html
*.css text
*.js text
*.sql text
*.csproj text merge=union
*.sln text merge=union eol=crlf
*.docx diff=astextplain
*.DOCX diff=astextplain
# absolute paths are ok, as are globs
/**/postinst* text eol=lf
# paths that don't start with / are treated relative to the .gitattributes folder
relative/path/*.txt text eol=lf
There is a convenient collection of ready to use .gitattributes files for the most popular programming languages. It's useful to get you started.
Once you've created or adjusted your .gitattributes
, you should perform a once-and-for-all line endings re-normalization.
Note that the GitHub Desktop app can suggest and create a .gitattributes
file after you open your project's Git repo in the app. To try that, click the gear icon (in the upper right corner) > Repository settings ... > Line endings and attributes. You will be asked to add the recommended .gitattributes
and if you agree, the app will also perform a normalization of all the files in your repository.
Finally, the Mind the End of Your Line article
provides more background and explains how Git has evolved
on the matters at hand. I consider this required reading.
You've probably got users in your team who use EGit or JGit (tools like Eclipse and TeamCity use them) to commit their changes. Then you're out of luck, as @gatinueta explained in this answer's comments:
This setting will not satisfy you completely if you have people working with Egit or JGit in your team, since those tools will just ignore .gitattributes and happily check in CRLF files https://bugs.eclipse.org/bugs/show_bug.cgi?id=342372
One trick might be to have them commit their changes in another client, say SourceTree. Our team back then preferred that tool to Eclipse's EGit for many use cases.
Who said software is easy? :-/
GIT - same directory but different OS behaving strange
You will want to read this article: https://help.github.com/articles/dealing-with-line-endings
Background: Windows uses a different line ending character than Unix and Mac. This is a constant source of grief and pain for cross platform software development. Sometimes, git "fixes" the line endings. This can be configured using the instructions in the above article. Git will then know that changes in the line endings don't mean that the file has changed.
Sometimes, your IDE notices "oh, the line endings are wrong for this platform" and fixes them. Since this happens without Git knowing, it will see "someone changed a lot of files".
A good way to determine what is going on is to use a powerful diff tool like kdiff3
. It will tell you things like "Text files are identical except for line endings" or you can see the line mode DOS vs. Unix near the file name when you compare files. See this question how to configure Git to use kdiff3: Using kdiff3 to edit diffs with git
Related Topics
How to Delete 5 Lines Before and 6 Lines After Pattern Match Using Sed
Sqlite Data File on Linux and Os X Incompatible
Program Life in Terms of Paged Segmentation Memory
How to Install Packages in Tcl
Cmakelist File to Generate Llvm Bitcode File from C Source File
How to Enable Mixed Mode Debugging in Visual Studio Code
Socket Send Concurrency Guarantees
Logging Memory Access Footprint
How Does Linux Kernel Prevents The Bios System Calls
Show Image Notification from Bash Script
Stty: Standard Input: Inappropriate Ioctl for Device
Udev Rules Are Not Working for Libusb on Ubuntu 12.04
Bash-Script Printing a PDF to a PDF in Linux
How to Identify Padding Scheme Used in Rsa Signature of a Certificate, Using Openssl
Example of Using External Libraries or Packages in Common Lisp