Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git-reset VS git-clean

Tags:

git

What exactly is the difference?

My goal is to completely restore the working tree to the state when it says "no changes" - no modifications or deletions, no new untracked files, nothing.

I don't care about the .gitignore-ed files.

like image 674
Geo Avatar asked Sep 17 '25 22:09

Geo


2 Answers

If you want to discard all uncommitted changes:

git reset --hard head

Which will basically restore all the files that Git knows about to their last committed state.

If you want to remove all the files that Git does not know about:

git clean -dxf

This will delete everything that is ignored or not tracked.

like image 156
Abizern Avatar answered Sep 19 '25 12:09

Abizern


git-reset

Reset current HEAD to the specified state.

for eg: git reset --hard HEAD^ - this will remove the top commit

git-clean

Used to remove untracked files/directories from working directory

like image 44
usha Avatar answered Sep 19 '25 14:09

usha