最近案子需要在不同的repo 之前推code,同时又想保留原来的git log 信息,基于此目的,查阅并整理git 关于此部分的使用方法。
假设:
我们当前的code 所在是,current_repo/current_branch,url 是url_current
目标推送code 位置是,targert_repo/target_branch, url 是url_target
我们可以这样做:
在current_repo/current_branch 这个目录下执行下面步骤,
1.git remote add target_repo url_target
2.git checkout -b target_branch
3.git push target_repo target_branch
如果失败,提示下面的error,
![remote rejected] xxx->xxx(shallow update not allowed)
这是因为,我们在git clone code 时使用了--depth=1, 导致拉取repo 信息不完整。
所以,需要第4步,
4.git fetch --unshallow current_repo
如果3.没有提示error,可以忽略此步骤。
5.再次执行git push target_repo target_branch