如何重命名 git 根文件夹?

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

我现在发现,在使用 git bash 时,文件夹名中的空间是一个小问题。

我能把文件夹重命名为 /path/to/project/gitrepo吗?Git 配置中的所有内容都是相对的吗,还是有明确指向父文件夹的内容?

我已经尝试了只获取一个主文件夹的 windows 副本,并在其上运行 git bash,‘ git log’显示了我之前所做的更改。因此,我假设重命名主文件夹是可以的,但是在进一步讨论之前,我想先确认一下。

50602 次浏览

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

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

(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 gitolite layer declaring your repos in a certain path, ...)
  • some operations use the full path of the repo (like the GIT_INDEX_FILE using within a filter-branch command for instance, see this thread), so, obviously, don't rename the root directory while performing a complex operation on your repo.

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.

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