简体   繁体   English

git如何清理克隆的存储库并重新克隆

[英]git how to clean a cloned repository and reclone

I am using a usb that i have cloned my repo, so i can transfer my work at home and vice versa. 我使用的是已克隆回购协议的USB,因此我可以在家中转移工作,反之亦然。 Many times the usb has problems and corrupts the repository. USB多次出现问题并损坏了存储库。 If I try to clean it and reclone it shows all the old (self) files as deleted, and all the origin's files as modified. 如果我尝试清理并重新克隆它,则所有旧(自)文件都将被删除,所有原始文件都将被修改。

I tried to clean the cloned repo by deleting folder or rename it, or event delete .git and reclone but it still shows old files as deleted. 我试图通过删除文件夹或重命名来清理克隆的存储库,或者通过事件delete .git和reclone进行清理,但是它仍显示已删除的旧文件。 Is there a way to fix it? 有办法解决吗?

I would really recommend, in order to have a clean version of your repo, to make a bundle . 我真的建议您使用一个干净的回购版本制作一个捆绑包
(See git bundle man page ). (请参见git bundle手册页 )。
Make sure you don't forget tags as well in your bundle . 确保您不要忘记捆绑包中的标签
Alternatives are discussed at " push vs. bundle vs. tar zcvf — to backup entire local .git ". 在“ push vs. bundle vs. tar zcvf —备份整个本地.git ”中讨论了替代方案。

That way, you get only one file to backup on your usb key (and you can clone/fetch from that bundle file). 这样,您只能在USB密钥上备份一个文件(并且可以从该捆绑文件中克隆/获取)。
One file is much harder to corrupt ;) 一个文件很难被破坏;)

You should be using a bare repository, that is one without a work tree, on the USB key. 您应该在USB密钥上使用一个没有工作树的存储库。 Bare repository is created with git init --bare or git clone --bare . 裸仓库是使用git init --baregit clone --bare

The "corruption" you are seeing is because git push does not update working directory of a non-bare target repository. 您看到的“损坏”是因为git push不会更新非裸露目标存储库的工作目录。 If the working copy is checked out from the branch you are pushing, it will result in invalid state of the working copy. 如果工作副本从您要推送的分支中签出,则将导致工作副本处于无效状态。

However, there is absolutely no reason to have a working copy there unless you mean to work directly from the USB key. 但是,除非您打算直接通过USB闪存进行工作,否则绝对没有理由在那里拥有工作副本。 So just don't create it, it's not needed for anything. 因此,不要创建它,它不需要任何东西。

If on the other hand you do intend to work off the USB key, either always pull to it (which does update the working copy, of course) or install appropriate hooks to update the working copy (there are two ways, depending on how you intend to work with it). 另一方面,如果您确实打算使用USB密钥,请始终将其拔出(当然,它确实会更新工作副本)或安装适当的钩子来更新工作副本(有两种方法,具体取决于您使用的方式)打算使用它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM