将现有代码指向 GIT 中远程存储库的新位置

Point existing code to new location of the remote respository in GIT

我在服务器上移动了我的远程存储库 (git) 并且路径发生了变化。但是,我错误地提交了一些更改,但忘记了 push 最后一次提交。现在推的时候还在老位置试。

我如何开始将相同的本地代码库指向新的 git 存储库,以便我可以继续工作而不必重新克隆存储库并重新应用未推送的更改?

git.exe push --progress "origin" master:master

remote: Not Found

fatal: repository 'http://server.com/username/repo-name.git/' not found

我自己想出来了:

需要手动更改 .git 文件夹下 config 文件中的 url 字段。这是一个隐藏文件夹(我知道,但之前没有看到所以没想到)。

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = http://server.com/new-value/repo-name.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

现在代码指向新的存储库位置,我可以推送

您可以使用以下命令将 link 更改为新的遥控器

git remote set-url origin {NEW URL.git}

您可以通过

验证此更改

git remote -v

以上命令假设远程仓库命名为"origin",默认命名为git,您可以根据自己的本地环境进行适当的更改。

可以在 https://help.github.com/articles/changing-a-remote-s-url/

找到更多详细信息