【问题标题】:Moving repository one hierarchy down without destroying commits在不破坏提交的情况下将存储库向下移动一个层次结构
【发布时间】:2019-12-06 21:41:18
【问题描述】:

所以现在我有这个文件夹结构:

\frontend
  -- .git/
  -- project 1 folder
  -- project 2 folder

现在我们决定将每个项目分别放在自己的仓库中,并更改每个项目的远程 url。

我怎样才能使它不会破坏我对project 1 folder 的提交历史记录,但是下次我执行git push 时,根文件夹现在将是project 1 folder 而不是frontend

我看到this 类似的问题,但接受的答案似乎是错误的(根文件夹仍然包含在提交中)

【问题讨论】:

    标签: git github directory git-remote


    【解决方案1】:

    我认为您链接到的答案确实是您想要的:Moving a git repository down a hierarchy level

    也许不清楚的是如何将它准确地应用于您的案例,因为您正在向上移动而不是向下移动。所以这里适合你的情况:

    # start with a fresh clone because you don't want any "dirty" files here!
    git clone <remote>/frontend.git
    # enter the fresh clone
    cd frontend
    # remove project 2 files
    rm -rf "project 2 folder"
    # move project 1 files up
    mv "project 1 folder"/* .
    rmdir "project 1 folder"
    # create massive change commit
    git add -A
    git commit -m "Moved project 1 up and removed project 2"
    git push
    

    现在,所有这些文件所在的文件夹 frontend 实际上并不是 repo 本身的一部分,而是它所在的名称。下次克隆时可以重命名:

    git clone <remote>/frontend.git "project 1 folder"
    

    这只会更改该克隆的名称。

    或者你可以在你的 Git 服务器上将 repo 本身重命名为“project 1 folder”.git,假设你的 Git 主机允许它。当然,这样做会使过去任何人从该仓库克隆的任何沙箱的远程 URL 无效,因此您必须修复这些问题。

    现在,问题是项目 2 已经消失了。我认为您可能需要做的是在您的 Git 服务器上创建两个新的存储库,每个项目一个。按照上述步骤,在git push 之前停止,然后改为:

    # Create "project 1 folder".git on your Git server and add it as a second remote
    git remote add p1 <remotes>/"project 1 folder".git
    # push to that remote instead of origin - list all branches you want to preserve
    git push p1 master
    

    然后重复以上所有内容,颠倒项目 1 和 2 的角色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-11
      • 2011-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 2020-02-03
      相关资源
      最近更新 更多