Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way to get a clean git sandbox?

For my continuous integration builds, I want to make sure no stray files have been deposited in my git sandbox, and none of the files have been inadvertently changed.

I know about git reset --hard HEAD, and this solves part of the problem. But I guess what I want to do is delete all the untracked and ignored files. I could do it the brute force way and just do:

rm -rf *
git checkout -f

But there must be a more efficient way to do it. Any ideas?

like image 218
mpontillo Avatar asked Mar 17 '12 00:03

mpontillo


1 Answers

(Expanded for posterity)

Your problem can be split in two: Returning modified files to their state in the last commit and removing any extra files that don't belong in the repository:

git reset --hard HEAD

will take your files back to the state they have in HEAD, removing any modifications (even if they were stage to be commited)

git clean -f -d -x

will remove any untracked files or directories, including ignored files (Thanks to @Jefromi)

like image 119
madth3 Avatar answered Nov 15 '22 21:11

madth3