繁体   English   中英

正确重新设置git分支

[英]Correctly rebasing git branch

我有一个类似以下的分支历史:

发展--- o ---- o
|
特征

我想在功能分支中进行更改,因此我做了以下工作

git checkout develop
git pull origin develop
git fetch origin feature:feature
git rebase develop

然后,我在功能分支中进行了更改。 现在,我尝试推动功能分支,我得到

error: failed to push some refs to 'https://github.com/test/test.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

这可能是由于远程分支未重新建立基础。 解决此问题的正确方法是什么? 我不想使用git push -f

假设您的本地develop分支是最新的,而远程develop分支是您需要做的

git checkout feature
git rebase origin/develop
git push origin feature --force

上面的操作是,您将本地feature分支与本地develop分支重新建立基础,因为我们假设您的本地和远程develop分支现在相同。

我还要指出的另一点是,当您从远程拉动时,请始终尝试拉动并重新设置其基准。 这样一来,您就始终知道本地<branchname>和远程<branchname>具有相同的副本,而无需进行separte变基。 这是您的操作方式。

git checkout <branchname>
git pull --rebase origin <branchname> 

暂无
暂无

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

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