移动一个git仓库

这个问题可能是愚蠢的,但我一直在想这个问题。 这是关于git仓库,但我认为其他DVCS的本地仓库是一样的。

可以说我的项目是这样的:

  • 项目
    • git的
    • 项目中的所有其他文件夹

所以当你把它设置正确的时候,它是如何工作的?

比方说,我把项目文件夹移到其他地方,我是否需要改变任何东西? 或者是.git文件夹中的所有存储库内容仅与项目文件夹相关,而忽略了Project上的整个文件树。

我很确定移动项目并不重要,但我只是想确保。

是的, .git所有内容都是相对的。 如果您已经将存储库作为另一个存储库的命名远程进行添加,则必须更改该存储库中的远程URL。

我发现子模块在git中不是相对的。

因此,如果要移动包含子模块的项目,则必须编辑子模块中的.git文件以及子模块configuration文件中的“worktree”属性,该文件存储在父级的.git/modules/MODULENAME/config文件。

显示当前的远程(当然这是可选步骤):

 $ git remote show origin * remote origin URL: git@oldserver:project.git Remote branch(es) merged with 'git pull' while on branch master master Tracked remote branches master 

我们需要做的是删除当前的原点,并添加新的:

 $ git remote rm origin $ git remote add origin git@newserver:project.git $ git remote show origin * remote origin URL: git@newserver:project.git Remote branch(es) merged with 'git pull' while on branch master master error: refs/remotes/origin/HEAD points nowhere! New remote branches (next fetch will store in remotes/origin) master 

不要担心最后一个命令显示的错误。 从原点拉第一次将解决它:

 $ git pull From git@newserver:project.git * [new branch] master -> origin/master Already up-to-date. $ git remote show origin * remote origin URL: git@newserver:project.git Remote branch(es) merged with 'git pull' while on branch master master Tracked remote branches master 

我还是新鲜的Git所以也许THE是一个更好的方式来做到这一点,但这对我工作。

不,你不需要改变别的东西。 那是

  • 假定没有脚本直接设置GIT_DIR,GIT_WORKTREE或GIT_INDEX(不太可能)
  • 您没有指向此副本的外部存储库

    • 如果你这样做,你将不得不重新使用它们

       git remote set-url [--push] origin user@yourhost:/home/user/newlocation/Project 

(起源应该是远程的名称; origin是从远程的repo克隆时的默认名称)

你可以把git目录从一台机器移到另一台机器上,或者说你想迁移你的项目文件夹。

所有关于origin的信息都存储在'.git'文件夹中,当你在你的系统目录下初始化一个git仓库的时候会创build这个文件夹。

程序

  1. :将项目文件夹移到其他位置。
  2. :如果项目文件夹正在移动到新的机器上,则创build相应的SSH密钥对。
  3. :告诉git你使用的是谁:git config –global user.email“your_git_email_id @ youremail”