我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
当前回答
如果你在Linux或Mac上有 sed/grep,它也很容易改变,而不会失去联系。
最近我做了这个改变我的用户名所有我的存储库在配置中本地,但我已经做到了相同的方法,远程线也完全。
VARIABLE_FIND='old'; VARIABLE_REPLACE='new'; path_name='~/PycharmProjects/*/.git/'; grep -rl --include=config "${VARIABLE_FIND}" "${path_name}" | xargs sed -i "s|${VARIABLE_FIND}|${VARIABLE_REPLACE}|g"
要替换整个线路,在那里有一个比赛,你可以这样做:
VARIABLE_FIND='someneedle'; VARIABLE_REPLACE='somenewvalue'; path_name='/home/*/' grep -rl --include=config "${VARIABLE_FIND}" "${path_name}" | xargs sed -i "/${VARIABLE_FIND//\//\\/}/c\\${VARIABLE_REPLACE}" ;
参考: 用 Sed 替换包含一条线的整个线
其他回答
这是非常容易和简单的;只需遵循这些指示。
要添加或更改远程起源: git 远程设置 URL 起源 githubrepurl 查看您目前在本地存储库中有哪些远程 URL: git 远程显示起源
正如我们在这里看到的那样,
$ git remote rm origin
$ git remote add origin git@github.com:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master
移除远程
使用 git 远程 rm 命令从您的存储库中删除远程 URL。
$ git remote -v
# View current remotes
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
> destination https://github.com/FORKER/REPOSITORY.git (fetch)
> destination https://github.com/FORKER/REPOSITORY.git (push)
$ git remote rm destination
# Remove remote
$ git remote -v
# Verify it's gone
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
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
另一种方法是重新命名“旧”起源(在下面的例子中,我简单地称之为旧起源),并添加一个新的。
git remote rename origin old-origin
git remote add origin git@new-git-server.com>:<username>/<projectname>.git
如果你需要推你的地方状态到新的起源:
git push -u origin --all
git push -u origin --tags