繁体   English   中英

如何撤消 git init --bare 在现有远程存储库中

[英]How to undo git init --bare in existing remote repository

我错误地在现有的远程存储库中运行了“git init --bare”。 Git 说它重新初始化了现有的 git 存储库。 有什么办法可以撤销这个动作?

实际上 'git init --bare' 只会将额外的文件添加到您的存储库中。 你可以删除它们。

% cd your-repo
% git status

untracked files:
(use "git add <file>..." to include in what will be committed)

    HEAD
    config
    description
    hooks/
    info/

% git clean -f -d

 Removing HEAD
 Removing branches/
 Removing config
 Removing description
 Removing hooks/
 Removing info/
 Removing objects/
 Removing refs/

您的目录现在像 'git init' 之前一样干净

我会 go 艰难的方式...将整个目录移动到备份目录,使用 repo 目录的先前名称创建一个新的空目录,然后将.git 目录从旧 repo 复制(递归)到新目录。 所以,假设你的仓库在 /home/blah/one_repo (在远程服务器上)

cd /home/blah
mv one_repo one_repo_back
mkdir one_repo
cp -R one_repo_back/.git one_repo/

如果您从另一台主机查看,repo 应该看起来像以前一样......现在,如果您还想找回工作树中的文件:

cd one_repo
git checkout -f the-branch
git reset --hard

你应该完成了。

暂无
暂无

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

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