如何在克隆的 git 存储库中撤消初始化
How to undo init in a cloned git repository
我有一个从远程主机克隆的 git 存储库。我 运行 错误地在本地克隆副本上初始化,我的错。因此,它现在是 git 和 git 远程等的 b运行d 新回购当然不显示与远程源的任何连接。我怎样才能 'reparent' 或再次告诉它它的远程来源是什么 is/was?
运行宁 git init
in an existing repository does not produce any harm. The documentation 说:
Running git init
in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init
is to pick up newly added templates (or to move the repository to another place if --separate-git-dir
is given).
至少它不会像你说的那样移除遥控器。您可能 运行 git init
在一个子目录中,它在那里创建了一个新的存储库。在这种情况下,git
在该子目录中创建了一个隐藏的 .git/
文件夹。找到它并删除它。
如果不是这种情况并且您克隆的存储库受到某种影响,则有一种简单的方法可以修复它。将原始存储库添加为远程并再次从中获取所有提交。
git remote add origin url-of-the-repo-you-cloned-before
git fetch origin
现在您的存储库包含远程存储库中存在的所有提交。你接下来做什么取决于你在发现提交消失之前做了什么。 运行 git status
来决定。如果您在正确的 b运行ch 上,那么您可以继续工作并在某个时候提交。如果你不在你想要的 b运行ch 上(或者你根本不在 b运行ch 上)那么你可以尝试 git checkout
b运行ch 你需要。如果它不起作用,因为它会替换您修改但未提交的文件,那么您必须存储您的更改,检查新的 b运行ch 并从存储中弹出更改(git stash
, git checkout correct-branch
, git stash pop
).
我有一个从远程主机克隆的 git 存储库。我 运行 错误地在本地克隆副本上初始化,我的错。因此,它现在是 git 和 git 远程等的 b运行d 新回购当然不显示与远程源的任何连接。我怎样才能 'reparent' 或再次告诉它它的远程来源是什么 is/was?
运行宁 git init
in an existing repository does not produce any harm. The documentation 说:
Running
git init
in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunninggit init
is to pick up newly added templates (or to move the repository to another place if--separate-git-dir
is given).
至少它不会像你说的那样移除遥控器。您可能 运行 git init
在一个子目录中,它在那里创建了一个新的存储库。在这种情况下,git
在该子目录中创建了一个隐藏的 .git/
文件夹。找到它并删除它。
如果不是这种情况并且您克隆的存储库受到某种影响,则有一种简单的方法可以修复它。将原始存储库添加为远程并再次从中获取所有提交。
git remote add origin url-of-the-repo-you-cloned-before
git fetch origin
现在您的存储库包含远程存储库中存在的所有提交。你接下来做什么取决于你在发现提交消失之前做了什么。 运行 git status
来决定。如果您在正确的 b运行ch 上,那么您可以继续工作并在某个时候提交。如果你不在你想要的 b运行ch 上(或者你根本不在 b运行ch 上)那么你可以尝试 git checkout
b运行ch 你需要。如果它不起作用,因为它会替换您修改但未提交的文件,那么您必须存储您的更改,检查新的 b运行ch 并从存储中弹出更改(git stash
, git checkout correct-branch
, git stash pop
).