简体   繁体   中英

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.

(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' (ie a stash).

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 .

您可以使用git stash来保存当前修改,然后您可以使用git stash apply来获取您的更改。

Try git reset --hard <revision>

See this page for good examples for the reset command: http://linux.die.net/man/1/git-reset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM