git | Version | EOL behavior |
---|---|---|
Official Git | 2.0.0 | Mixed EOL |
Git for Windows | 1.9.4 | Mixed EOL |
libgit2-based software | 0.21.0-rc1 | All CRLF |
- Set core.autocrlf = false
- Add/Commit all files with different EOLs
- Set core.autocrlf = true
Based on https://github.com/msysgit/msysgit/wiki/Vagrant
- Installe Virtual Box
- Installe Vagrant
- Run C:\msysGit\msys.bat
- Run
vagrant up
- Run
vagrant ssh
- Run
sudo apt-get install python-software-properties
- Run
sudo add-apt-repository ppa:git-core/ppa
- Run
sudo apt-get update
- Run
sudo apt-get install git
- Run
git --version
showsgit version 2.0.0
- Run
cd /vagrant
- Run
git clone https://github.com/YueLinHo/TestAutoCrlf.git
- Run
cd TestAutoCrlf
- Run
git config core.autocrlf true
- Delete all files in the working tree via Windows Explorer.
- Run
git checkout HEAD -f -- "MIX-more_LF.txt"
- Got the file with mixed EOLs
- Run
git checkout HEAD -f -- "MIX-more_CRLF.txt"
- Got the file with mixed EOLs
(Check the EOL via Notepad++ on Windows)
Double check : Run Step 3-5, 10-11, 13-17
$ git checkout HEAD -f -- "MIX-more_LF.txt"
$ git checkout HEAD -f -- "MIX-more_CRLF.txt"
Still mixed EOLs
- Delete them
- TortiseGit -> Revert
Still mixed EOLs
- Open TortoiseGit Log Message dialog
- Click the commit which add all file
- Right click on testing file
- Click "Save revision to..."
All CRLF EOLs
I use VS2013 to trace the source code. Called function are:
- git_blob_filtered_content() of blob.c
- git_filter_list_apply_to_blob() of filter.c
- git_filter_list_apply_to_data() of filter.c
- fe->filter->apply() (crlf_apply() of crlf.c)
- crlf_apply_to_workdir() of crlf.c
- line_ending() of crlf.c
- git_buf_text_lf_to_crlf() of buf_text.c
- git_buf_put() of buffer.c
- crlf_apply_to_workdir() of crlf.c
- fe->filter->apply() (crlf_apply() of crlf.c)
- git_filter_list_apply_to_data() of filter.c
- git_filter_list_apply_to_blob() of filter.c
And...
in the line_ending(),
ca->crlf_action is -1 (GIT_CRLF_GUESS)
ca->eol is 0 (GIT_EOL_UNSET)
And line_ending() return "\r\n" finally. (GIT_EOL_NATIVE == GIT_EOL_CRLF is true)
Maybe I will re-trace the source code to get where the var ca is set.