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
  • 338
  • 2
  • 13
  • 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
  • 120,984
  • 8
  • 59
  • 111
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
  • 35,025
  • 12
  • 111
  • 136