git 如何重置“本地”git存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18079433/
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 to reset "local" git repository?
提问by Wosh
I was trying to ignore some folders when pushing and ended up with only the .gitignore
in the repository. Now want to "reset" my repository (by reset I mean to remove all the rules I applied and clean the commit area), so that I can add all my files and remove the folders I don't want after that. Any help?
我试图在推送时忽略一些文件夹,但最终只有.gitignore
存储库中的 。现在想“重置”我的存储库(重置我的意思是删除我应用的所有规则并清理提交区域),以便我可以添加所有文件并删除我不想要的文件夹。有什么帮助吗?
回答by Morgan
You could just delete your .git folder and start again.
您可以删除 .git 文件夹并重新开始。
rm -rf .git
git init
This will leave the current .gitignore in place, which would still be followed by the new git repo. The .gitignore could be removed, or delete the contents so it is a blank file.
这将使当前的 .gitignore 保持原状,新的 git repo 仍将紧随其后。.gitignore 可以被删除,或者删除内容使其成为一个空白文件。
回答by lukassteiner
If you want to create the repository again, then just remove the .git directory.
如果要再次创建存储库,只需删除 .git 目录。
回答by Simson
If you do not need a clean history just remove the files from the repository and commit your changes. If you would like to revert to an earlier commit there is a git reset command
如果您不需要干净的历史记录,只需从存储库中删除文件并提交您的更改。如果你想恢复到较早的提交,有一个 git reset 命令
git reset --hard HEAD^
Here is some more info How to undo last commit(s) in Git?
这里有更多信息如何撤消 Git 中的最后一次提交?