Reputation: 7270
I have setup Git so it doesn't commit inconsistent line endings. The problem with that is a whole pile of files appear modified even though they are not. What do I type to make these files have the line endings fixed on the local side?
# git checkout dev
M src/au/policy/dao/EmailQueue.java
M src/au/policy/dao/EmailQueueFactory.java
M src/au/policy/dao/PolicyPublisher.java
Already on 'dev'
# git diff
warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueue.java
warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueueFactory.java
warning: LF will be replaced by CRLF in src/au/policy/dao/PolicyPublisher.java
This is what I added to my git config file which seems to do what I intended aside from this issue:
autocrlf = true
Upvotes: 53
Views: 61068
Reputation: 7110
I had this problem when creating new Xcode project. My solution for this problem:
In terminal write
git config --global --edit
Then in git config file change safecrlf to false. My settings:
[core]
autocrlf = input
safecrlf = false
I know git have cmd line tools for this but they don't work for me. And then Xcode create git repos without any problem.
Upvotes: 40
Reputation: 2428
In my case, after setting autocrlf variable to true, then running
git stash
and then
git stash pop
everything cleared out
Upvotes: 0
Reputation: 181
Note that note all of the above fixes may work for you, for example you might have received the code through a simple file transfer. You can accept each warning by pressing ENTER, but on on large repos that can take ages. Another way to ignore the conversion on code that has already been checked-out and edited is to create a patch file:
git diff > changes.patch
Upvotes: 2
Reputation: 323544
This might happen if you change core.autocrlf
config variable (if I understand your problem correctly).
If you are at clean state, i.e. just after commit, and you don't have uncomitted changes, forced re-checkout and removing index should do the trick:
The below command
git reset --hard HEAD
will make your current branch to point to the latest commit and all uncommitted code will be lost. Make sure to commit the code or take the backup
$ rm .git/index
$ git reset --hard HEAD
That, I think, would sync both working area files, and the index (staging area) to follow crlf settings.
Upvotes: 63
Reputation: 33239
Only thing I can think of is to check if core.safecrlf
is set to warn
.
git config --get core.safecrlf
I think possible values are true
, false
, and warn
. I believe that setting to false
will resolve the warning, though it may not be a good idea.
Upvotes: 26
Reputation: 41
Try this, it worked for me:
cd src/au/policy/dao
dos2unix
If there are other files in that folder, then you'll want to break it up into the following (otherwise it will try to do it on every file in any subdirectories, which may take a while):
cd src/au/policy/dao
dos2unix EmailQueue.java
dos2unix EmailQueueFactory.java
dos2unix PolicyPublisher.java
It ran really quick on my machine and fixed all of the line endings, and it's a little simpler and easier than some of these other fixes.
Upvotes: 2
Reputation: 792009
You can just delete and re-checkout the offending files from the index like this:
rm <files>
git checkout -- <files>
Or, if they are the only modified files (be careful with this command), you can script it like this:
git diff --name-only --diff-filter=M | xargs rm --
git checkout -- .
On a GNU system you can use a slightly safer pipe, but you don't appear to have spaces or other delimiting characters in your filenames in any case.
git diff -z --name-only --diff-filter=M | xargs -0 rm --
Upvotes: 16