如何重命名 Git 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2041993/
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 rename a Git repository?
提问by Yantao Xie
git mv
renames a file or directory in a repository. How do I rename the Git repository itself?
git mv
重命名存储库中的文件或目录。如何重命名 Git 存储库本身?
回答by Alex Brown
There are various possible interpretations of what is meant by renaming a Git repository: the displayed name, the repository directory, or the remote repository name. Each requires different steps to rename.
对于重命名 Git 存储库的含义,有多种可能的解释:显示名称、存储库目录或远程存储库名称。每个都需要不同的步骤来重命名。
Displayed Name
显示名称
Rename the displayed name (for example, shown by gitweb
):
重命名显示的名称(例如,显示为gitweb
):
- Edit
.git/description
to contain the repository's name. - Save the file.
- 编辑
.git/description
以包含存储库的名称。 - 保存文件。
Repository Directory
存储库目录
Git does not reference the name of the directory containing the repository, as used by git clone master child
, so we can simply rename it:
Git 不引用包含存储库的目录的名称,正如 所使用的那样git clone master child
,因此我们可以简单地重命名它:
- Open a command prompt (or file manager window).
- Change to the directory that contains the repository directory (i.e., do not go into the repository directory itself).
- Rename the directory (for example, using
mv
from the command line or the F2hotkey from a GUI).
- 打开命令提示符(或文件管理器窗口)。
- 切换到包含存储库目录的目录(即,不要进入存储库目录本身)。
- 重命名目录(例如,
mv
从命令行使用或F2从 GUI使用热键)。
Remote Repository
远程仓库
Rename a remote repository as follows:
重命名远程存储库,如下所示:
- Go to the remote host (for example, https://github.com/User/project).
- Follow the host's instructions to rename the project (will differ from host to host, but usually Settingsis a good starting point).
- Go to your local repository directory (i.e., open a command prompt and change to the repository's directory).
- Determine the new URL (for example,
[email protected]:User/project-new.git
) Set the new URL using Git:
git remote set-url origin [email protected]:User/project-new.git
- 转到远程主机(例如,https://github.com/User/project)。
- 按照主机的说明重命名项目(因主机而异,但通常设置是一个很好的起点)。
- 转到您的本地存储库目录(即,打开命令提示符并更改到存储库的目录)。
- 确定新 URL(例如,
[email protected]:User/project-new.git
) 使用 Git 设置新 URL:
git remote set-url origin [email protected]:User/project-new.git
回答by Tobu
A Git repository doesn't have a name. You can just rename the directory containing your worktree if you want.
Git 存储库没有名称。如果需要,您可以重命名包含工作树的目录。
回答by Alex
Rename PRJ0.git
to PROJ1.git
, then edit the URL variable located in the .git/config
file of your project.
重命名PRJ0.git
为PROJ1.git
,然后编辑位于.git/config
项目文件中的 URL 变量。
回答by mholm815
In a new repository, for instance, after a $ git init
, the .git directory will contain the file .git/description.
例如,在新存储库中,在 a 之后$ git init
,.git 目录将包含文件 .git/description。
Which looks like this:
看起来像这样:
Unnamed repository; edit this file 'description' to name the repository.
Unnamed repository; edit this file 'description' to name the repository.
Editing this on the local repository will not change it on the remote.
在本地存储库上编辑它不会在远程更改它。
回答by Droogans
If you meant renaming your repository, go to your repository and click "admin", then rename.
如果您要重命名您的存储库,请转到您的存储库并单击“管理员”,然后重命名。
Once you see the red box warning you about some sky-fallingness and other things, go read this question.
一旦你看到红色框警告你一些天空坠落和其他事情,去阅读这个问题。
回答by Neha Kumari
To rename any repository of your GitHub account:
要重命名 GitHub 帐户的任何存储库:
- Go to that particular repository which you want to rename
- Navigate to the settings tab
- There, in the repository name section, type the new name you want to put and click Rename
- 转到要重命名的特定存储库
- 导航到设置选项卡
- 在那里,在存储库名称部分,键入要放置的新名称,然后单击 Rename
回答by Parison
On the server side, just rename the repository with the mvcommand as usual:
mv oldName.git newName.git
Then on the client side, change the value of the
[remote "origin"]
URL into the new one:url=example.com/newName.git
在服务器端,只需像往常一样使用mv命令重命名存储库:
mv oldName.git newName.git
然后在客户端,将
[remote "origin"]
URL的值更改为新的值:url=example.com/newName.git
It worked for me.
它对我有用。
回答by avi.elkharrat
If you are using GitLab or GitHub, then you can modify those files graphically.
如果您使用的是 GitLab 或 GitHub,那么您可以以图形方式修改这些文件。
Using GitLab
使用 GitLab
Go to your project Settings. There you can modify the name of the project and most importantly you can rename your repository (that's when you start getting in the danger section).
转到您的项目设置。在那里你可以修改项目的名称,最重要的是你可以重命名你的存储库(那是你开始进入危险部分的时候)。
Once this is done, local clients configurations must be updated using
完成此操作后,必须使用更新本地客户端配置
git remote set-url origin sshuser@gitlab-url:GROUP/new-project-name.git
回答by Danny Remington - OMS
If you are in Eclipse and have installed Egit then you can rename the repository that contains a project by doing the following:
如果您在 Eclipse 中并安装了 Egit,那么您可以通过执行以下操作来重命名包含项目的存储库:
1) In Eclipse: Close all projects that are in the repository.
1)在 Eclipse 中:关闭存储库中的所有项目。
2) In the file system: Locate the directory/folder that contains the repository.
2)在文件系统中:找到包含存储库的目录/文件夹。
3) In the file system: Rename the directory/folder that contains the repository.
3)在文件系统中:重命名包含存储库的目录/文件夹。
4) In the file system: Open the directory/folder that contains the repository and rename the project directory/folder of any project you intend to rename so that it will match the new name of the project. (This is not required but it gives consistency between the project name in Eclipse and the project directory/folder in the repository.)
4)在文件系统中:打开包含存储库的目录/文件夹,并重命名您要重命名的任何项目的项目目录/文件夹,使其与项目的新名称匹配。(这不是必需的,但它使 Eclipse 中的项目名称与存储库中的项目目录/文件夹保持一致。)
5) In Eclipse: Delete all projects that are in the repository but be sure to NOTcheck the 'Delete the contents from the file system' checkbox. (The project should no longer contain the correct location of the contents of the file system so the data could not be deleted in any case but it is better to be safe than sorry.)
5)在 Eclipse 中:删除存储库中的所有项目,但一定不要选中“从文件系统中删除内容”复选框。(该项目不应再包含文件系统内容的正确位置,因此无论如何都无法删除数据,但安全总比抱歉好。)
6) In Eclipse: From the Menu select the File|Import... option.
6)在 Eclipse 中:从菜单中选择 File|Import... 选项。
7) In Eclipse: In dialog box open the 'Git' folder, select 'Projects from Git' and click 'Next'.
7)在 Eclipse 中:在对话框中打开“Git”文件夹,选择“Projects from Git”并单击“Next”。
8) In Eclipse: In dialog box select 'Local' and click 'Next'.
8)在 Eclipse 中:在对话框中选择“本地”并单击“下一步”。
9) In Eclipse: In dialog box click the 'Add...' button.
9)在 Eclipse 中:在对话框中单击“添加...”按钮。
10) In Eclipse: In dialog box make sure the check box next to the repository is checked and click 'Finish'.
10)在 Eclipse 中:在对话框中确保选中存储库旁边的复选框,然后单击“完成”。
11) In Eclipse: In dialog box select the repository and click 'Next'.
11)在 Eclipse 中:在对话框中选择存储库并单击“下一步”。
12) In Eclipse: In dialog box select the 'Import existing projects' radio button, select the "Working Directory" and click 'Next'.
12)在 Eclipse 中:在对话框中选择“导入现有项目”单选按钮,选择“工作目录”并单击“下一步”。
13) In Eclipse: In dialog box check the check box next to the projects you want to work on and click 'Finish'.
13)在 Eclipse 中:在对话框中选中您要处理的项目旁边的复选框,然后单击“完成”。
14) In Eclipse: Rename any the projects that are in the repository if so desired. (For consistency between Eclipse and the file system give them the same name as the project directory/folder inside the repository directory/folder.)
14)在 Eclipse 中:如果需要,重命名存储库中的任何项目。(为了 Eclipse 和文件系统之间的一致性,为它们提供与存储库目录/文件夹中的项目目录/文件夹相同的名称。)
回答by Ujjwal Singh
Git itself has no provision to specify the repository name. The root directory's name is the single source of truth pertaining to the repository name.
Git 本身没有规定指定存储库名称。根目录的名称是与存储库名称有关的唯一真实来源。
The .git/description
though is used only by some applications, like GitWeb.
在.git/description
虽然仅由某些应用程序,如使用的GitWeb。