Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git 仓库迁移应该怎么操作【热度: 160】 #666

Open
yanlele opened this issue Jan 12, 2024 · 0 comments
Open

git 仓库迁移应该怎么操作【热度: 160】 #666

yanlele opened this issue Jan 12, 2024 · 0 comments
Labels
web应用场景 应用场景类问题 小米 公司标签
Milestone

Comments

@yanlele
Copy link
Member

yanlele commented Jan 12, 2024

关键词:git 仓库迁移

如果你想迁移仓库并保留原始仓库的所有提交历史、分支和标签,你可以使用以下步骤:

方法一:使用 git clonegit push

  1. 在仓库 B 中创建新的仓库。

  2. 在本地克隆仓库 A:

git clone --mirror <仓库 A URL>
cd <仓库 A 目录>

使用 --mirror 选项克隆仓库会保留所有分支、标签和提交历史。

  1. 修改远程仓库地址为仓库 B:
git remote set-url --push origin <仓库 B URL>
  1. 推送到仓库 B:
git push --mirror

方法二:使用 git bundle

  1. 在仓库 A 中创建 bundle 文件:
git bundle create repoA.bundle --all
  1. repoA.bundle 文件传输到仓库 B 所在位置。

  2. 在仓库 B 中克隆:

git clone repoA.bundle <仓库 B 目录>

这两种方法都会保留所有分支、标签和提交历史。选择哪种方法取决于你的具体需求和迁移环境。

注意:

  • 使用 --mirror--all 选项在 git clonegit bundle 中时,会将所有的分支和标签复制到目标仓库。
  • 在执行之前,请确保仓库 B 是空的或者是一个你可以覆盖的目标仓库,因为这些操作会覆盖目标仓库的内容。
  • 如果仓库 A 中包含子模块,你可能需要额外处理子模块的迁移。
@yanlele yanlele added web应用场景 应用场景类问题 小米 公司标签 labels Jan 12, 2024
@yanlele yanlele added this to the milestone Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web应用场景 应用场景类问题 小米 公司标签
Projects
None yet
Development

No branches or pull requests

1 participant