How to rename git root folder?

◇◆丶佛笑我妖孽 提交于 2019-12-18 10:17:41

问题


I've just started using git in Vista, with my repository under /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.

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?

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.


回答1:


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.




回答2:


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




回答3:


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:

  • get the old directory in sync with your git server (git pull, git push and at last git status to see if everything is fine)
  • 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 :)




回答4:


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



来源:https://stackoverflow.com/questions/7199659/how-to-rename-git-root-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!