Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do a pristine checkout with git?

How do I return my working directory to the state it would be in if I made a new clone and checked out the current version?

For subversion I'd do:

$ svn status --no-ignore | awk '$1 == "?" { print $2 }' | xargs rm -r

and for mercurial:

$ hg status --ignored --unknown | awk  ' ( $1 == "?" ) || ( $1 == "I") { print $2 }' | xargs rm -r

So answers in the same line are fine. But something like git checkout --clean -r b4a23 would be better.

like image 547
John Lawrence Aspden Avatar asked Feb 06 '12 19:02

John Lawrence Aspden


2 Answers

(prepare to loose all local, uncommited changes:)

git reset --hard
git clean -dfx .

As mentioned, you can use git stash to temporarily save a reference to your local pending changes on a 'pseudo branch' (i.e. a stash).

like image 197
sehe Avatar answered Oct 18 '22 03:10

sehe


In addition to @sehe's answer, you may want to create an alias to make it easier.

git config --global alias.pristine '!git reset --hard && git clean -dffx'

Then you may just call git pristine.

like image 43
Joris Valette Avatar answered Oct 18 '22 01:10

Joris Valette