gpt4 book ai didi

git - 如何将现有的 Git 存储库导入另一个?

转载 作者:IT王子 更新时间:2023-10-29 01:10:37 25 4
gpt4 key购买 nike

我在名为 XXX 的文件夹中有一个 Git 存储库,我还有一个名为 YYY 的 Git 存储库。

我想将XXX 仓库导入YYY 仓库作为一个名为ZZZ 的子目录,并添加所有XXX> 的更改历史记录为 YYY

之前的文件夹结构:

├── XXX
│ ├── .git
│ └── (project files)
└── YYY
├── .git
└── (project files)

之后的文件夹结构:

YYY
├── .git <-- This now contains the change history from XXX
├── ZZZ <-- This was originally XXX
│ └── (project files)
└── (project files)

这可以做到吗,还是我必须求助于使用子模块?

最佳答案

可能最简单的方法是将 XXX 内容 pull 入 YYY 中的分支,然后将其 merge 到 master 中:

YYY 中:

git remote add other /path/to/XXX
git fetch other
git checkout -b ZZZ other/master
mkdir ZZZ
git mv stuff ZZZ/stuff # repeat as necessary for each file/dir
git commit -m "Moved stuff to ZZZ"
git checkout master
git merge ZZZ --allow-unrelated-histories # should add ZZZ/ to master
git commit
git remote rm other
git branch -d ZZZ # to get rid of the extra branch before pushing
git push # if you have a remote, that is

实际上,我只是用我的几个 repo 协议(protocol)尝试了这个并且它有效。不像Jörg's answer它不会让您继续使用其他存储库,但我认为您无论如何都没有指定。

注意:由于这是2009年写的,所以git添加了下面答案中提到的子树 merge 。我今天可能会使用那个方法,当然这个方法仍然有效。

关于git - 如何将现有的 Git 存储库导入另一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1683531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com