使用子模块
将需要保留的分支作为一个独立的仓库,并使用子模块的方式引入到单仓库中。这样可以保留分支的历史记录和代码,并与单仓库中的其他代码集成。以下是代码示例:
git clone
cd
git checkout -b myfeature
# add some code and commit
git push origin myfeature
git submodule add myfeature
cd myfeature
git checkout myfeature
cd ..
git add myfeature
git commit -m "Add myfeature submodule"
这样做可以保留分支代码和历史记录,并可以在单仓库中继续修改和集成。当需要更新子模块时,只需切换到子模块分支并进行更新,然后更新主仓库即可。
cd myfeature
git pull origin myfeature
cd ..
git add myfeature
git commit -m "Update myfeature submodule"
下一篇:保留分组时的列