我如何 git clone git://foo.git AGAIN?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1248535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can i git clone git://foo.git AGAIN?
提问by
I did git clone git://foo.git cd foo ...edit files..
我做了 git clone git://foo.git cd foo ...edit files..
now I want to start fresh. I don't care about any changes I already made,
but I don't want to clone the whole giant foo.git again, just lose all my changes.
how can i git clone git://foo.git a second time, without getting
fatal: destination path 'foo' already exists and is not an empty directory.
what is the proper command?
现在我想重新开始。我不在乎我已经做的任何更改,但我不想再次克隆整个巨大的 foo.git,只是丢失我所有的更改。我怎样才能 git clone git://foo.git 第二次,没有得到
fatal: destination path 'foo' already exists and is not an empty directory.
什么是正确的命令?
回答by d0k
git checkout . # revert your changes
git clean -xdf # delete untracked and ignored files
回答by Jakub Nar?bski
You can use "git checkout ." or "git checkout HEAD -- .", or even "git reset --hard HEAD" to reset your working area to known state (to state recorded in index in first case, to state recorded in HEAD commit in second and third case).
您可以使用“git checkout”。或“git checkout HEAD -- .”,甚至“git reset --hard HEAD”将您的工作区重置为已知状态(在第一种情况下记录在索引中的状态,在第二种和第三种情况下记录在 HEAD 提交中的状态) .
To delete untracked files you don't want to keep you can use "git clean" (see documentation for details).
要删除您不想保留的未跟踪文件,您可以使用“git clean”(有关详细信息,请参阅文档)。
To get new changes from remote repository you cloned from, use "git fetch" (or equivalent "git remote update", after some setup), or "git pull" (to fetch andmerge changes).
要从您克隆的远程存储库中获取新更改,请使用“git fetch”(或等效的“git remote update”,经过一些设置)或“git pull”(获取和合并更改)。
回答by Sinan Taifour
To revert all your changes, use:
要还原所有更改,请使用:
git checkout .
Untracked files (files that didn't originally exist in the tree, ones you created and not edited) will not be removed, though. To find the untracked files, use:
但是,未跟踪的文件(树中最初不存在的文件,您创建但未编辑的文件)不会被删除。要查找未跟踪的文件,请使用:
git status
Then delete them manually.
然后手动删除它们。
By the way, if you'd like to make a copy of the repo, you don't need to clone the original repo, you can simply clone the one you already have on your hard disk. Go somewhere outside foo
, and do:
顺便说一句,如果你想复制一份 repo,你不需要克隆原始 repo,你可以简单地克隆你硬盘上已有的那个。去外面的某个地方foo
,然后做:
git clone /path/to/foo
回答by rfunduk
If you reallyscrew it up:
如果你真的搞砸了:
git clean -df
git reset --hard HEAD
回答by f.svehla
You can also always use
您也可以随时使用
rm -rf *
git checkout master
Less commands to remember :)
要记住的命令更少:)