什么是最有效的方式来获得一个干净的git沙箱? [英] What is the most efficient way to get a clean git sandbox?
问题描述
对于我的持续集成构建,我想确保没有寄存文件存放在我的git沙箱中,没有任何文件被无意中更改。
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.
我知道 git reset --hard HEAD
,这解决了部分问题。但我想我想要做的是删除所有未跟踪和忽略的文件。我可以做强力的方式,只是做:
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?
推荐答案
(为后代扩展)
您的问题可以分为两部分:将修改的文件恢复到上次提交时的状态,并删除不属于存储库的任何额外文件:
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
回到他们在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
将删除所有未跟踪的文件或目录,包括忽略的文件(感谢@Jefromi)
will remove any untracked files or directories, including ignored files (Thanks to @Jefromi)
这篇关于什么是最有效的方式来获得一个干净的git沙箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!