简体   繁体   English

Git-将本地分支移动到其他远程分支

[英]Git - Moving a local branch to different remote branch

I want to move my local branch, from one remote branch to another. 我想将本地分支从一个远程分支移动到另一个分支。 my local_branch is based on remotes/kernel/132, and I move it to the remotes/kernel/142. 我的local_branch基于remotes / kernel / 132,我将其移至remotes / kernel / 142。 Here is the list of my branches: 这是我的分支机构列表:

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

I already changed some part of the code, and have committed. 我已经更改了部分代码,并已提交。 However, I don't want to push the local_branch to the remotes/kernel/132, but I want to move it to remotes/kernel/142 and push it to this remote branch. 但是,我不想将local_branch推送到remotes / kernel / 132,但是我想将其移动到remotes / kernel / 142并将其推送到此远程分支。 The config file shows this: 配置文件显示以下内容:

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

I want to change it to: 我想将其更改为:

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

"Moving" the commits is called a rebase . “移动”提交称为rebase This doesn't really move the commits, but it creates new commits on the new base, which apply the same changes as the old commits applied to the old base. 这并没有真正动提交,但它创造了新的基础上,新的提交,适用作为老的提交应用到旧基同样的变化。 The ref does move (from the old commits to the new ones); ref确实会移动(从旧提交到新提交); and since you haven't pushed these commits (and presumably don't have other refs that can reach them) it's a textbook instance where rebasing should work pretty cleanly. 而且由于您还没有推送这些提交(并且可能没有其他引用可以到达它们),因此这是一个教科书实例,其中的变基应该非常干净。

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

The new commits represent untested states of the code, so some testing is in order at this point. 新的提交表示代码的未测试状态,因此在此时需要进行一些测试。

The other part of the question you can handle with git config 您可以使用git config处理的问题的另一部分

git config branch.local_branch.merge refs/heads/142

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM