我有一个带有react-app的A存储库和一个在Github上有一些ML代码的B存储库。两个存储库都有一些提交,我想将我的提交保留在 A 存储库中并将其添加到 B 存储库中。这样我就可以继续在 B 存储库 (ML) 上进行提交。我该怎么做?
我尝试正常将文件添加到 B 存储库,但它不保留提交。
克隆您的存储库 B
git clone <repository B URL>
导航到克隆的存储库 B 目录并将存储库 A 添加为远程。
cd <repository B directory>
git remote add repoA <repository A URL>
从存储库 A 获取提交。
git fetch repoA
将存储库 A 的提交合并到存储库 B 的主分支中
git merge repoA/main # or the branch from Repository A you want to merge
如果存储库 A 的提交与存储库 B 中的现有代码之间存在任何冲突,请手动解决。还要保持目录结构兼容
git commit -m "Merge commits from Repository A"
将更改推送到存储库 B。
git push origin main
现在,您可以像往常一样继续处理存储库 B 并提交更改。