stdcall
stdcall

Reputation: 28860

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 ?

Upvotes: 6

Views: 830

Answers (2)

madhead
madhead

Reputation: 33374

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.

Upvotes: 4

VonC
VonC

Reputation: 1323183

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.

Upvotes: 5

Related Questions