On Windows, I would like to check out all linux shell files (.sh) with LF line endings
Line Endings of other text-based files should be converted to CRLF. (which is handled via the global core.autocrlf=true)
- global .gitconfig
[core]
editor = 'C:/Tools/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
autocrlf = true
- .gitattributes in repository root folder
*.sh text eol=lf
I used git add --renormalize . when adding the .gitattributes file.
Unfortunately the .sh files still have CRLF after checkout.
additional information: One of my team members did change his global core.autocrlf=false some commits ago, which caused the chaotic line endings, I guess.
With above mentioned steps I could at least fix files of the local repository to have CRLF endings again.
steps tried:
- delete files locally and checkout again: no affect - all CRLF
- delete files, push deletion, recreate files with LF: still CRLF after checkout
- manually change line endings with Notepad++...
user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf)
$ git status
On branch bug_sh_files_eol_lf
Your branch is up to date with 'origin/bug_sh_files_eol_lf'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: production_code/build_production_code.sh
modified: test_code/unit_tests/create_unit_test_xml.sh
no changes added to commit (use "git add" and/or "git commit -a")
user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf)
$ git add . -u
warning: LF will be replaced by CRLF in production_code/build_production_code.sh.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in test_code/unit_tests/create_unit_test_xml.sh.
The file will have its original line endings in your working directory
user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf)
$ git status
On branch bug_sh_files_eol_lf
Your branch is up to date with 'origin/bug_sh_files_eol_lf'.
nothing to commit, working tree clean
user@workstation MINGW64 /c/repos/project-source (bug_sh_files_eol_lf)
*.shfiles and checking them out again to be on the safe side.*.shfiles that have CRLF line endings in the committed version of the file. (Normally, withcore.autocrlf = true, this wouldn't happen, but there are various ways to make it happen, after which the files stay that way, in commit after commit, until you change them.) If this is the case then the thing to do is fix the file once, manually, e.g., withdos2unix, add, and commit..gitattributesentry will handle things for all new commits. But note: if this guess is wrong, then after usingdos2unixor equivalent andgit add, Git will say that there is nothing to commit.