移动后如何修复本地 git repo 的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14465326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I fix the path of my local git repo after move?
提问by Whitecat
How do I fix the path of my local git repo after move?
移动后如何修复本地 git repo 的路径?
previous local location: /C/website
new local location: /C/Projects/website
remote location: [email protected]:username/website.git
I moved my git repository from one folder /website
to another /projects/website
and now I get an error:
我将我的 git 存储库从一个文件夹移动/website
到另一个文件夹/projects/website
,现在出现错误:
user@Thinkpad /C/Projects/website (master)
$ git push
fatal: 'C:/website' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Is there any way to fix this without having to re-clone the project? I tried:
有没有办法解决这个问题而不必重新克隆项目?我试过:
$ git init
Reinitialized existing Git repository in c:/Projects/website/.git/
It that did nothing and I got the exact same error again when I tried to push.
它什么也没做,当我尝试推送时,我再次遇到了完全相同的错误。
Edit:
编辑:
I ran: git config remote.origin.url C:/Projects/website
. Now when I commit after changing files I get the following reply:
我跑了:git config remote.origin.url C:/Projects/website
。现在,当我在更改文件后提交时,我得到以下回复:
user@Thinkpad /C/Projects/website (master)
$ git commit -m "added something"
[master e163ad9] added something
0 files changed
create mode 100644 something
user@Thinkpad /C/Projects/website (master)
$ git push
Everything up-to-date
回答by fge
Run git config -e
and change the address of the remote, to the correct remote location. In your case that will be url = [email protected]:username/website.git
This command will open for editing the .git/config
file of the repository.
运行git config -e
并将远程地址更改为正确的远程位置。在您的情况下,url = [email protected]:username/website.git
此命令将打开以编辑.git/config
存储库的文件。
(thanks to @Richard for the command)
(感谢@Richard 的命令)
Shortcut command:
快捷指令:
git config remote.origin.url [email protected]:username/website.git
回答by knittl
You have to update the origin
remote to the new url:
您必须将origin
遥控器更新为新网址:
git remote set-url origin '/C/Projects/website'
git remote set-url origin '/C/Projects/website'
If you just move a local clone, you don't have to do anything to update the pointers to bitbucket or other hosting services. Just move the folder including everything (the .git
directory is essential).
如果您只是移动本地克隆,则无需执行任何操作来更新指向 bitbucket 或其他托管服务的指针。只需移动包含所有内容的文件夹(.git
目录是必不可少的)。
回答by Shaishab Roy
If you used SmartGityou can change repository url by this way
如果您使用SmartGit,您可以通过这种方式更改存储库 url
open smartGit and double click on your repository and go to menu
Remote>Properties..
and set new repository path to path or url.
打开 smartGit 并双击您的存储库并转到菜单
Remote>Properties..
并将新存储库路径设置为path or url.