Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git reset - ignoring specific untracked files

Often, I execute git reset --hard along with git clean -f in order to clean-up my branch from modifications and build files. This command, deletes all the untracked files, which is OK for me, but there are few files I want to stay, such as .project or .settings (for eclipse)

These file are not part of the repository, and declared in the .gitignore file. is there a way to keep these files when issuing the above commands, or maybe I should you different commands for that ?

like image 272
stdcall Avatar asked Jan 20 '13 10:01

stdcall


People also ask

Does git reset remove untracked files?

git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !


2 Answers

Note that git clean -f should only removed files unknown to git, not ignored files.

Only git clean -f -x would removed ignored files.

(in all cases, a git clean -n -... is better, to have a preview of what would be removed)

The advantage of git reset over git clean is mainly about moving HEAD and resetting the index as well as the working tree.
git clean is only about the working tree.

like image 129
VonC Avatar answered Sep 21 '22 12:09

VonC


git reset will not touch ignored files. It works with HEAD pointer and index, mostly. But git clean is the evil:

Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

So the answer is: do not use git clean.

like image 26
madhead - StandWithUkraine Avatar answered Sep 19 '22 12:09

madhead - StandWithUkraine