简体   繁体   English

如何使用git进行原始结帐?

[英]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: 对于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. 但是像git checkout --clean -r b4a23会更好。

(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). 如上所述,您可以使用git stash临时保存对“伪分支”(即存储)上的本地挂起更改的引用。

In addition to @sehe's answer , you may want to create an alias to make it easier. 除了@ sehe的答案之外 ,您可能还想创建一个别名以使其更容易。

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

Then you may just call git pristine . 然后你可以打电话给git pristine

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

Try git reset --hard <revision> 尝试git reset --hard <revision>

See this page for good examples for the reset command: http://linux.die.net/man/1/git-reset 有关reset命令的详细示例,请参阅此页面: http//linux.die.net/man/1/git-reset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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