Git使用原仓库初始化新仓库
2025年2月21日小于 1 分钟
使用原仓库初始化新仓库
- 初始化新仓库或直接拉取新仓库
初始化
mkdir new-repo
cd new-repo
git init
或直接拉取
git clone <new-repo-url> new-repo
cd new-repo
- 添加原仓库
git remote add old-repo <old-repo-url>
- 拉取原仓库文件
git fetch old-repo --depth=1
- 检出原仓库文件并标记起点
git checkout old-repo/master
git tag old-base old/master
- 创建孤儿分支
git checkout --orphan master
- 提交原仓库文件到新仓库
git add .
git commit -m <commit-message>
- 推送到新仓库
git remote add origin <new-repo-url>
git push origin master
合并后续提交
- 拉取原仓库最新提交
git fetch old-repo
- 获取需要合并的提交列表
git log old-base..old-repo/master --reverse --pretty=%H
- 逐个应用提交(并解决冲突)
git cherry-pick <hash1> <hash2>
- 更新合并起点
git tag -f old-base old-repo/master