All of our developers work on windows machines and build is done on Linux.
In order to conform the true way we decided to normalize line endings and follow scenario described on GitHub.
Later it appeared that from time to time when switching from one branch to another, some files are marked as changed while no content changes are detected.
Then I came across with GitBook documentation on line endings and its normalization.
So I wonder what is the difference between these two approaches?:
git rm --cached -r .
# Remove everything from the index.
git reset --hard
# Write both the index and working directory from git's database.
git add .
# Prepare to make a commit by staging all the files that will get normalized.
# This is your chance to inspect which files were never normalized. You should
# get lots of messages like: "warning: CRLF will be replaced by LF in file."
git commit -m "Normalize line endings"
# Commit
and
$ rm .git/index # Remove the index to force git to
$ git reset # re-scan the working directory
$ git status # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"
Because these two gives different set of files in git status
.
And when should I push normalized files to a remote?
UPD: Here is a situation I have when running git commands and switching between branches:
>git status
on develop, no changes
>git checkout -t origin/BRANCH-1 && git status
Branch BRANCH-1 set up to track remote branch GPIII-96 from origin.
Switched to a new branch 'BRANCH-1'
modified: A.java
modified: B.java
modified: C.java
>file A.java
A.java: ASCII text, with CRLF line terminators
>git rm --cached -r . && git reset --hard && git status
# On branch BRANCH-1
nothing to commit (working directory clean)
*WTF??*
>git checkout develop -f && git status
modified: D.java
*WTF???*
>git checkout BRANCH-1 -f && git status
modified: A.java
modified: B.java
modified: C.java
*WTF???*
I did had the same problem once. I can only give you one advice.
For me its not the work of a VCS to manage our line endings. Its the job of the developer or the IDE. So normalize your line endings once and after that switch the line endings on the windows machine IDEs to Unix-Line-Endings and be happy again. Thats what solved our problems.
来源:https://stackoverflow.com/questions/22790758/on-git-line-endings-again