Home > OS >  Git clean before or after git reset?
Git clean before or after git reset?

Time:04-22

Occasionally I want to change my git working copy to a pristine state. I do this with the following two commands:

git clean -dxf
git reset --hard

Is there any reason to run clean before or after reset? No matter what kind of crazy situation I have got my repo into, could running them in one order or the other ever fail or not get me back to where I want to be, as if I had a clean checkout?

Might I ever need to do something even more complicated like clean-reset-clean?

CodePudding user response:

Is there any reason to run clean before or after reset?

Yes. git clean responds to the state of the index. git reset --hard changes the state of the index. So git clean needs to be run after the index state is corrected, which is what git reset --hard does.

Might I ever need to do something even more complicated like clean-reset-clean?

No.


Note: This answer is not intended as an endorsement of saying git clean -dxf. It merely responds to the specific question on its own terms.

  •  Tags:  
  • git
  • Related