git 如何重命名git根文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7199659/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:41:43  来源:igfitidea点击:

How to rename git root folder?

gitdirectoryrename

提问by Mick O'Hea

I've just started using git in Vista, with my repository under /path/to/project/git repo.

我刚刚开始在 Vista 中使用 git,我的存储库在/path/to/project/git repo.

I've now found that the space in the folder name is a minor irritation when working in git bash.

我现在发现在 git bash 中工作时文件夹名称中的空格是一个小问题。

Can I just rename the folder to /path/to/project/gitrepo? Is everything within the git config relative, or is there anything that explicitly refers to the parent folder?

我可以将文件夹重命名为/path/to/project/gitrepo吗?git config 中的所有内容是否都是相对的,或者是否有任何明确引用父文件夹的内容?

I've tried just taking a windows copy of the main folder, and run git bash on that, and 'git log' shows the changes I had previously made. So I assume renaming the main folder is OK, but I'd like to be sure before I go any further.

我试过只获取主文件夹的 Windows 副本,然后在其上运行 git bash,“git log”显示我之前所做的更改。所以我认为重命名主文件夹是可以的,但我想在继续之前确定。

采纳答案by VonC

To amend slightly Greg's answer, yes, everything with a git repo is relative to the .gitparent directory, but:

要稍微修改Greg答案,是的,带有 git repo 的所有内容都相对于.git父目录,但是:

(and this won't probably affect you directly, I only mention those reasons here for completeness' sake.):

(这可能不会直接影响您,为了完整起见,我仅在此处提及这些原因。):

  • the path of the repo itself could be referenced by other services running on your computer (Apache, ssh, another repo declaring your repo as a remote, using the full file path, a gitolitelayer declaring your repos in a certain path, ...)
  • some operations use the full path of the repo (like the GIT_INDEX_FILEusing within a filter-branchcommand for instance, see this thread), so, obviously, don't rename the root directory while performing a complex operation on your repo.
  • 存储库本身的路径可以被您计算机上运行的其他服务引用(Apache、ssh、另一个将您的存储库声明为远程存储库、使用完整文件路径、在某个路径中声明您的存储库的gitolite层,...... )
  • 某些操作使用存储库的完整路径(例如GIT_INDEX_FILEfilter-branch命令中使用,请参阅此线程),因此,显然,在对存储库执行复杂操作时不要重命名根目录。

Plus, a "windows copy" (instead of a git clone), will copy everything including hooks, which may include absolute path in their script if you have edited them and made those kind of modification.

另外,“Windows 副本”(而不是git clone)将复制包括钩子在内的所有内容,如果您编辑了它们并进行了此类修改,则它们的脚本中可能包含绝对路径。

回答by Greg Hewgill

Yes, it is safe to rename the folder containing a Git repository. All paths inside the Git repository are relative.

是的,重命名包含 Git 存储库的文件夹是安全的。Git 存储库中的所有路径都是相对的。

回答by PythoNic

Please check the comments first...

请先查看评论...

In my opinion, the best is to use the git workflow, especially when you use a git server (remote master repository), which means:

在我看来,最好是使用git 工作流,尤其是当你使用 git 服务器(远程主存储库)时,这意味着:

  • get the old directory in sync with your git server (git pull, git pushand at last git statusto see if everything is fine)
  • git clone <former directory> <new directory>
  • 得到同步旧目录与你的git服务器(git pullgit push,最后git status,看看是否一切都很好)
  • git clone <former directory> <new directory>

(Since I'm also new to GIT, this might be not the full, correct answer. I've had the same question as Mick and for learning purpose I tried to do it the git way :) Thanks for the clue, vonC! Please correct me, if needed :)

(因为我也是 GIT 的新手,这可能不是完整的、正确的答案。我和 Mick 有同样的问题,为了学习目的,我尝试用 git 的方式来做:)谢谢你的线索,vonC!如果需要,请纠正我:)

回答by Akshay Kumar

yes you can change it. your repo still direct to your git.. just do not remove/edit name of .git fo

是的,你可以改变它。你的 repo 仍然直接指向你的 git .. 只是不要删除/编辑 .git fo 的名称