我怎么能克隆git://foo.git再次?

14 git clone

我做了git clone git://foo.git cd foo ...编辑文件..

现在我想重新开始.我不关心我已经做出的任何改变,但我不想再次克隆整个巨人foo.git,只是失去我所有的改变.我怎么能第二次git克隆git://foo.git,却没有得到 fatal: destination path 'foo' already exists and is not an empty directory. 正确的命令?

d0k*_*d0k 10

git checkout . # revert your changes
git clean -xdf # delete untracked and ignored files
Run Code Online (Sandbox Code Playgroud)

  • 注意:git checkout.如果你不在你的回购顶部,显然是行不通的.`git reset --hard`将普遍适用. (5认同)

Sin*_*our 2

要恢复所有更改,请使用:

git checkout .
Run Code Online (Sandbox Code Playgroud)

不过,未跟踪的文件(树中最初不存在的文件,您创建但未编辑的文件)将不会被删除。要查找未跟踪的文件,请使用:

git status
Run Code Online (Sandbox Code Playgroud)

然后手动删除它们。

顺便说一句,如果您想制作存储库的副本,则无需克隆原始存储库,只需克隆硬盘上已有的存储库即可。去外面的某个地方foo,然后做:

git clone /path/to/foo
Run Code Online (Sandbox Code Playgroud)