git repoA cp本地repoB的指定commit

发布时间:2026/7/18 18:18:45

git repoA cp本地repoB的指定commit 方法一添加 remote cherry-pick推荐# 1. 进入目标仓库 repoBcd /path/to/repoB# 2. 把 repoA 添加为 remote只读不 pushgit remote add repoA /path/to/repoA# 3. 拉取 repoA 的所有分支信息git fetch repoA# 4. 查看 repoA 指定分支上的提交历史找到你要 cherry-pick 的 commit hashgit log repoA/branch-name --oneline# 5. cherry-pick 单个或多个提交git cherry-pick commit-hash-1git cherry-pick commit-hash-2 commit-hash-3 # 多个# 6. 可选完成后清理 remotegit remote remove repoA方法二直接路径引用不需要 remote# 如果 repoA 已经 fetch 过repoB 可以直接引用它的对象cd /path/to/repoB# 直接从 repoA 的 .git 目录读取指定分支的提交git --git-dir/path/to/repoA/.git log branch-name --oneline# cherry-pick 时指定来源git cherry-pick commit-hash# 如果遇到对象找不到先GIT_ALTERNATE_OBJECT_DIRECTORIES/path/to/repoA/.git/objects git cherry-pick commit-hash

相关新闻