Git - 将本地分支移动到不同的远程分支

Git - Moving a local branch to different remote branch

我想将我的本地分支从一个远程分支移动到另一个。我的 local_branch 是基于 remotes/kernel/132,我把它移到了 remotes/kernel/142。这是我的分支列表:

git branch -a
* local_branch 
remotes/kernel/132
remotes/kernel/142 

我已经更改了部分代码,并已提交。但是,我不想将local_branch推送到remotes/kernel/132,而是想将其移动到remotes/kernel/142并将其推送到此远程分支。 配置文件显示:

[branch "local_branch"]
    remote = kernel
    merge = refs/heads/132

我想改成:

[branch "local_branch"]
    remote = kernel
    merge = refs/heads/142

"Moving" 提交称为 rebase。这不会真正 移动提交,但它会在新基础上创建新提交,它应用与应用于旧基础的旧提交相同的更改。 ref 确实移动了(从旧提交到新提交);并且由于您没有推送这些提交(并且可能没有其他可以访问它们的引用)这是一个教科书实例,其中变基应该非常干净地工作。

git rebase --onto kernel/142 kernel/132 local_branch

新提交代表代码的未测试状态,因此此时需要进行一些测试。

你可以用 git config

处理问题的另一部分
git config branch.local_branch.merge refs/heads/142