如何重新启动 git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15244644/
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 restart a git repository
提问by JimH
I am a newbie with git – and just realized changes to the .gitignore does not process against the repo “retroactively” – rather affect future ‘git add *' commands and the like. Once the files are in the repo – they must be manually removed.
我是 git 的新手——刚刚意识到对 .gitignore 的更改不会“追溯”地处理 repo——而是影响未来的“git add *”命令等。一旦文件在 repo 中 - 它们必须手动删除。
At this point – I would like just kill this repo entirely – and start over (saving my config, etc.).
在这一点上——我只想完全终止这个 repo——然后重新开始(保存我的配置等)。
Is this easily possible or would it cause major problems? Can backup – then delete the .git folder – and start fresh?
这很容易实现还是会导致重大问题?可以备份 - 然后删除 .git 文件夹 - 并重新开始吗?
Also – for others newbies just starting in git I would suggest viewing this video. It describes not how to use git – but how git works internally – and I found it eye opening. It's titled git for ages 4 and up. http://blip.tv/open-source-developers-conference/git-for-ages-4-and-up-4460524
另外 - 对于刚开始使用 git 的其他新手,我建议观看此视频。它描述的不是如何使用 git——而是 git 如何在内部工作——我发现它大开眼界。它的标题是 git,适合 4 岁及以上。 http://blip.tv/open-source-developers-conference/git-for-ages-4-and-up-4460524
Resolution:
解析度:
I want to thank everyone for their input and guidance.
我要感谢大家的投入和指导。
I did try to delete the .git directory - and restart. I am not sure how - but when I did try to start it over - It started up with full awareness of it's history - and in short recreated itself to include all the previous commits and tracking.
我确实尝试删除 .git 目录 - 并重新启动。我不确定如何 - 但是当我确实尝试重新开始它时 - 它开始时完全了解它的历史 - 简而言之,重新创建自己以包含所有以前的提交和跟踪。
I left that alone - and set about reorganizing and restructuring and cleaning. Changing the folder structure - deleted unnecessary projects, folders, etc.. - and in the process - realized what I could do to remove the files I did not want tracked (but still wanted them present in the tree).
我不理会它——并着手进行重组、重组和清理。更改文件夹结构 - 删除了不必要的项目、文件夹等。 - 在此过程中 - 意识到我可以做些什么来删除我不想跟踪的文件(但仍然希望它们出现在树中)。
I effectively moved every folder, etc. and when I would commit this - git removed the tracking on the moved / deleted files. But because of the .gitignore I now had - it did not pick up or track the files in the moved folders.
我有效地移动了每个文件夹等,当我提交时 - git 删除了对移动/删除文件的跟踪。但是由于我现在拥有的 .gitignore - 它没有拾取或跟踪移动文件夹中的文件。
Much of what I was doing was in preparation to start a whole new git repo. Late in the process I't dawned on me - most of what I did not want tracked had been effectively been removed for the repo. So took what had happened - and made a few more adjustments - and all is fine now.
我所做的大部分工作都是为开始一个全新的 git 仓库做准备。在这个过程的后期,我并没有意识到 - 我不想跟踪的大部分内容已经被回购有效地删除了。因此,接受所发生的一切 - 并进行了更多调整 - 现在一切都很好。
Once again - thank you. I'm loving git!
再次 - 谢谢。我爱吉特!
回答by JohnNY
I do this all the time. got into the working directory and if your on linux or mac do a
我一直这样做。进入工作目录,如果您在 linux 或 mac 上执行
rm -rf .git
then I do a
然后我做一个
git init
git add .
git commit -m "first time load"
that's all you need
这就是你所需要的
回答by berkes
Can backup – then delete the .git folder – and start fresh?
可以备份 - 然后删除 .git 文件夹 - 并重新开始吗?
Yes. This is all there is to it.
是的。这就是它的全部内容。
Some really exotic set-ups might have the .git folder outside of the working directory; but otherwise the .git folder contains all the information there is wrt git. If you remove that, you remove all history, git-metadata and such.
一些非常奇特的设置可能在工作目录之外有 .git 文件夹;但除此之外,.git 文件夹包含了 git 中的所有信息。如果删除它,则会删除所有历史记录、git-metadata 等。
If you had remotes, the link to them is lost, as that is stored in the same .git folder. The remote itself, on say your Gitlab server, is obviously not gone. So if you re-add that same remote on your clean environment it will cause history to re-appear, which might cause merge conflicts.
如果你有遥控器,它们的链接就会丢失,因为它存储在同一个 .git 文件夹中。远程本身,比如你的 Gitlab 服务器,显然没有消失。因此,如果您在干净的环境中重新添加相同的遥控器,它将导致历史记录重新出现,这可能会导致合并冲突。
Edit: for those who might not have read the entire question: warning: this will remove all your git history.
编辑:对于那些可能没有阅读整个问题的人:警告:这将删除您所有的 git history。
回答by dionyziz
The best strategy for handling this would be to use the git archive
command. This will export an unversioned version of your tree in a tar archive. Select your branch that you'd like to export and run the following inside your repository:
处理此问题的最佳策略是使用该git archive
命令。这将在 tar 存档中导出树的未版本控制版本。选择您要导出的分支并在您的存储库中运行以下命令:
git archive master | tar -x -C ~/target/directory
You can then cleanly delete your repository folder and then extract your archive to start anew. Finally, you can create a new repository in your extracted folder as follows:
然后,您可以彻底删除存储库文件夹,然后提取存档以重新开始。最后,您可以在提取的文件夹中创建一个新的存储库,如下所示:
git init