我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
当前回答
更改主机为 Git Origin 服务器
从: http://pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/
希望这不是你需要做的事情,我已经使用的服务器在一些 git 项目上合作,域名终止了,这意味着找到一个方式来迁移当地存储库以恢复同步。
更新: 感谢 @mawolf 指出,最近的 git 版本有一个简单的方式(发表于 2010 年 2 月):
git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git
如果你有更古老的版本,那就尝试一下:
在工作目录中编辑.git/config 文件,您应该看到如下:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git
更改 oldhost.com 到 newhost.com,保存文件,你已经完成了。
从我的有限测试(git pull 起源; git push 起源; gitx)一切似乎顺序。
其他回答
(仅限 Windows PS) 在所有本地休息室中重复更改服务器/协议
Get-ChildItem -Directory -Recurse -Depth [Number] -Hidden -name | %{$_.replace("\.git","")} | %{git -C $_ remote set-url origin $(git -C $_ remote get-url origin).replace("[OLD SERVER]", "[NEW SERVER]")}
git remote -v
# View existing remotes
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL
git remote -v
# Verify new remote URL
# origin https://github.com/user/repo2.git (fetch)
# origin https://github.com/user/repo2.git (push)
更改远程的URL
如果您想在原始URL中设置用户名和密码,您可以遵循下面的步骤。
输出密码在变量将避免与特殊字符的问题。
步骤:
export gituser='<Username>:<password>@'
git remote set-url origin https://${gituser}<gitlab_repo_url>
git push origin <Branch Name>
更改主机为 Git Origin 服务器
从: http://pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/
希望这不是你需要做的事情,我已经使用的服务器在一些 git 项目上合作,域名终止了,这意味着找到一个方式来迁移当地存储库以恢复同步。
更新: 感谢 @mawolf 指出,最近的 git 版本有一个简单的方式(发表于 2010 年 2 月):
git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git
如果你有更古老的版本,那就尝试一下:
在工作目录中编辑.git/config 文件,您应该看到如下:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git
更改 oldhost.com 到 newhost.com,保存文件,你已经完成了。
从我的有限测试(git pull 起源; git push 起源; gitx)一切似乎顺序。
如果您正在使用 TortoiseGit 然后遵循下面的步骤:
转到您的本地查询文件夹,然后右键单击转到 TortoiseGit -> 设置 在左键中选择 Git -> Remote 在右键中选择起源 现在更改 URL 文本框值到您的新远程存储库的位置
你的分支和所有的地方承诺将保持不稳定,你可以继续像以前那样工作。