Git cannot undo modified files

I just want to return to a clean working directory, exactly the same as after my last commit. Git tells me to download file changes that I did not make, so I suspect this is due to the end of the line.

I tried all the usual suspects to do this:

git reset --hard git commit -- . git stash git clean -fd

No matter what I do, git status always shows the same files as the changed ones. What can I do? I have uncommitted changes hidden in another branch, so I donโ€™t just want to destroy everything, but just โ€œroll backโ€ my master branch.

EDIT: Exit

 $ git status # 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: demo/index.html # modified: demo/js/app.js # modified: demo/js/libs/jquery.1.7.1.js # modified: demo/js/libs/matchMedia.js # modified: demo/js/libs/modernizr.js # modified: demo/js/loadr.js # modified: dist/enquire.js # modified: src/include/intro.js # no changes added to commit (use "git add" and/or "git commit -a") 

Then I try what is offered and everything else that I could find:

 WickyNilliams at Nick MBA in ~/Repositories/enquire on master* $ git checkout -- . WickyNilliams at Nick MBA in ~/Repositories/enquire on master* $ git reset --hard HEAD is now at d70fee4 added meta tag to test demo on mobile #10 WickyNilliams at Nick MBA in ~/Repositories/enquire on master* $ git status # 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: demo/index.html # modified: demo/js/app.js # modified: demo/js/libs/jquery.1.7.1.js # modified: demo/js/libs/matchMedia.js # modified: demo/js/libs/modernizr.js # modified: demo/js/loadr.js # modified: dist/enquire.js # modified: src/include/intro.js # no changes added to commit (use "git add" and/or "git commit -a") 

As you can see, no change, despite the rollback.

So, I followed the advice and ran diff, ignoring the whole space, and it is believed that there seems to be no difference when ignoring spaces - so I think these were line endings! What can I do to fix this? I set autocrlf to true no avail.

+4
source share
3 answers

If you just want to change the file as it was after the last commit, just do git checkout [file] to get a specific file. But git reset --hard had to do this for the whole tree. If you think these are just strings, do git diff and then a git diff --ignore-all-space . If the first diff shows the changes and the second does not, then at least you know that you have a problem with line endings, in which case you can see this description of git and line endings .

+4
source

Try the approach described in the โ€œRe-normalizing the repoโ€ section of this github article , making sure your EOL settings have reasonable values โ€‹โ€‹(for your OS and repo policy)

+2
source

If Git thinks your files have changed due to attempts to automatically normalize line endings (which would be true if git diff shows differences, but git diff --ignore-all-space does not), the best solution would be to disable line endings for your project . This works well if your team uses the same platform (Windows, Linux, etc.) for a given set of files.

To disable line ending modification for your project, open or create .gitattributes in the root of your repository. Make sure the file contains the following line:

 * -text 

If the file exists and has a different setting for * , for example * text=auto , replace it with the line above.

0
source

Source: https://habr.com/ru/post/1438775/


All Articles