Skip to content

Instantly share code, notes, and snippets.

@gabetax
Created April 4, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabetax/2304167 to your computer and use it in GitHub Desktop.
Save gabetax/2304167 to your computer and use it in GitHub Desktop.
git autocrlf input example
gabebug@Gabe-Work ~/Sites $ git init crlf
Initialized empty Git repository in /Users/gabebug/Sites/crlf/.git/
gabebug@Gabe-Work ~/Sites $ cd crlf/
gabebug@Gabe-Work ~/Sites/crlf $ git config core.autocrlf
input
gabebug@Gabe-Work ~/Sites/crlf $ vim crlf.txt
gabebug@Gabe-Work ~/Sites/crlf $ xxd crlf.txt
0000000: 610d 0a62 0d0a 630d 0a a..b..c..
gabebug@Gabe-Work ~/Sites/crlf $ git add crlf.txt
warning: CRLF will be replaced by LF in crlf.txt.
The file will have its original line endings in your working directory.
gabebug@Gabe-Work ~/Sites/crlf $ git ci -m "add crlf"
[master (root-commit) 77861ec] add crlf
warning: CRLF will be replaced by LF in crlf.txt.
The file will have its original line endings in your working directory.
1 files changed, 3 insertions(+), 0 deletions(-)
create mode 100644 crlf.txt
gabebug@Gabe-Work ~/Sites/crlf[master] $ xxd crlf.txt
0000000: 610d 0a62 0d0a 630d 0a a..b..c..
gabebug@Gabe-Work ~/Sites/crlf[master] $ git co crlf.txt
gabebug@Gabe-Work ~/Sites/crlf[master] $ xxd crlf.txt
0000000: 610d 0a62 0d0a 630d 0a a..b..c..
gabebug@Gabe-Work ~/Sites/crlf[master] $ rm crlf.txt
gabebug@Gabe-Work ~/Sites/crlf[master*] $ git co crlf.txt
gabebug@Gabe-Work ~/Sites/crlf[master] $ xxd crlf.txt
0000000: 610a 620a 630a a.b.c.
gabebug@Gabe-Work ~/Sites/crlf[master] $ perl -pi -e 's/\n/\r\n/g' crlf.txt
gabebug@Gabe-Work ~/Sites/crlf[master*] $ xxd crlf.txt
0000000: 610d 0a62 0d0a 630d 0a a..b..c..
gabebug@Gabe-Work ~/Sites/crlf[master*] $ git st
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: crlf.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
gabebug@Gabe-Work ~/Sites/crlf[master*] $ git add crlf.txt
warning: CRLF will be replaced by LF in crlf.txt.
The file will have its original line endings in your working directory.
gabebug@Gabe-Work ~/Sites/crlf[master] $ git st
# On branch master
nothing to commit (working directory clean)
gabebug@Gabe-Work ~/Sites/crlf[master] $ xxd crlf.txt
0000000: 610d 0a62 0d0a 630d 0a a..b..c..
@gabetax
Copy link
Author

gabetax commented Apr 4, 2012

A few conclusions about autocrlf=input

  • a file created with CRLF will be committed as LF in the repository, but will be left alone as-is in your working directory
  • if a file was committed with CRLF's, the CRLF's will not show the file modified, but changing another file with LF -> CRLF will show that file as modified
  • git add on a file with only CRLF -> LF or LF -> CRLF changes cause the file to no longer show as modified and will not appear on the stage

If you're in a scenario where you have rsync an export (with changes) of the repository on to your repository to commit them, and the export has CRLFs in it, just running a git add on every file will make your change list ignore the CRLFs. An easy way to do this for pre-existing files is:

git ls-files --cached -z | xargs -0 git add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment