Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove unstaged changes [newline characters difference] in git?

Tags:

git

This is frustrating and I simply can't find the right answer on how to handle this. I am after a rebase [but this is just one of many scenarios where this problem occurs] and I have a ton of files "changed but not updated" that have no difference but for the newline characters.

git diff -b

nothing returned.

Now I just want to remove the changes and leave files as they are in the repo. I've found plenty of "solutions":

1 Stashing changes
a) with --keep-index [this was actually from SO]

$ git stash save --keep-index
Saved working directory and index state WIP on COM-23: 4a8abc1 COM-23 changed pa
ckage name
HEAD is now at 4a8abc1 COM-23 changed package name

$ git stash drop
Dropped refs/stash@{0} (7d822e3c6bdc310f4a4be90ed937dd0ea97df627)

$ git status
[tons of files marked as changed but not updated]

b) without --keep-index
exactly the same as with 'a'

2 git reset
a) just a reset

git reset --hard HEAD

same as above

b) with add

git add -A
git reset --hard HEAD

same as above

3 checkout

git checkout

same as above, status returns a lot of unstaged files.

I am quite certain I am doing something wrong or just misunderstanding the problem, but all I want to do is to get rid of the unstaged changes! How can I do that?

Thanks, Krystian

like image 454
Krystian Avatar asked Nov 19 '10 00:11

Krystian


1 Answers

Check out git config [--global] core.autocrlf. It's best to have it set to false. You may still need a git reset --hard after changing that value, because you have to sync your editor newlines settings with those of Git.

like image 75
Ionuț G. Stan Avatar answered Sep 27 '22 22:09

Ionuț G. Stan