Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the behavior of git status showing modified files which are eventually not committed?

I am working in a windows-only working environment with developers using all kinds of tools to edit their files. We are using .git along with the atlassian stack to version our code. I like almost all of it.

I have just recently finished fighting a long and hard fight to wrap my head around how and why git interprets line endings and what core.autocrlf does. We've decided to use core.autocrlf true and all is almost well.

I would LOVE to know how to change this behavior of git status:

  • I have a file with CRLF line endings.
  • I change the line endings to LF

    $ git status
    On branch somebranch
    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:   Src/the_file_i_changed_to_LF.js
    
  • But then...

    $ git commit -a
    warning: LF will be replaced by CRLF in Src/the_file_i_changed_to_LF.js.
    The file will have its original line endings in your working directory.
    On branch somebranch
    nothing to commit, working directory clean
    

To this one:

  • I have a file with CRLF line endings.
  • I change the line endings to LF

    $ git status
    On branch somebranch
    nothing to commit, working directory clean
    
  • which makes sense since nothing will get committed anyway.

Is this possible?

I believe the possible duplicate does not hold the answer I am looking for. I would like to emphasize that I do (think I) know what my setting core.autocrlf true does and want to keep it that way. What I'm interested in is either not detecting changes in git status which will not be committed anyway, or understanding why this is not possible.

like image 296
jhnwsk Avatar asked Sep 03 '15 10:09

jhnwsk


1 Answers

When you set core.autocrlf true all files in your working directory will have CRLF line ending (regard less of the actual line ending in the repository). For most windows users this is good enough.

From your question I understand you want to have your working directory files (=local file) with LF. So, here you should be using core.autocrlf input. This will give you the exact line ending as in the repository (but still it will make sure all check-ins are made with LF).

Read more about the difference of true, false, input in this answer.

like image 175
Chananel P Avatar answered Sep 20 '22 15:09

Chananel P