Does someone know of a better way to re-checkout all files in the working directory than the following?
In other words, I want to force overwrite every file in the working directory, with the cached copy of a certain commit ref, regardless of whether or not the files have been modified.

Here's how I'm currently doing it:

rm -rf *
git checkout <ref> .

This works, but deletes untracked files, and doesn't delete hidden .files. Of course, I don't want to delete .git, but I do want other .files to be affected.
I could come up with a more complete way to delete all the files in the working directory, but a solution that stays within Git would be ideal.

Why I want to do this: changing AutoCRLF
Files have not been modified, but need to be rewritten from the cache.
The ref I'm using is simply HEAD, so git checkout ., but I wanted to generalize the question to any commit or branch.


For this problem, let's assume that the working directory is clean (unmodified). If you have changes, you can always git stash before doing this.

  • Git is going to make this difficult for you, since it doesn't want you to lose unsaved work. Does git stash followed by git checkout work for you? – Tomas Zubiri May 14 at 18:46
  • No, git stash doesn't affect unmodified files. Let's assume no files are modified. OP edited to clarify this. – SilentStorm May 15 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.