1

I have used git reset --hard however it has left files the were just created and not committed. Is that by design? Is there an easy way to clear all these files as well?

kevin
  • 171
  • 10
  • 3
    Does this answer your question? [git reset --hard HEAD leaves untracked files behind](https://stackoverflow.com/questions/4327708/git-reset-hard-head-leaves-untracked-files-behind) – Andrei Kovrov Nov 10 '20 at 20:55

2 Answers2

2

Is that by design?

Yes.

Is there an easy way to clear all these files as well?

git clean -fd
KamilCuk
  • 96,430
  • 6
  • 33
  • 74
2

git reset --hard changes all files in the index, but not the untracked files, as you noticed.

You can use (note: DANGEROUS because irreversible. Removed files cannot be recovered.):

git clean -dfx

if you want to remove all untracked files. The options:

  • -d : remove directories as well
  • -f : force = really remove (when you leave out this flag, it is a "dry-run")
  • -x : remove also files ignored by .gitignore
Chris Maes
  • 30,644
  • 6
  • 98
  • 124