简体   繁体   English

重新设置后的Git分支在远程后面

[英]Git branch behind remote after rebase

I'm getting in problems with git. 我在使用git时遇到问题。 I wanted to rebase a branch hotfix over master local and remote, both, so this is what I did. 我想基于master本地和远程(两者)重新构建分支hotfix ,所以这就是我所做的。

git checkout hotfix
git pull hotfix              #just getting someone changes
git fetch origin master
git rebase origin/master

After a long time resolving conflicts and rebuilding project I have it working ok, so I have to upload the changes to the remote branch. 经过长时间的解决冲突并重建项目,我可以正常运行,因此必须将更改上传到远程分支。

git push origin hotfix

And this is waht git thinks: 这是git认为的:

$ git push origin login2
To https://name@bitbucket.org/***/***.git
 ! [rejected]        hotfix -> hotfix (non-fast-forward)
error: failed to push some refs to 'https://name@bitbucket.org/***/***.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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I have tried: 我努力了:

git pull --rebase

But this gives same conflicts like before the other rebase and it shoudln't. 但这会产生与其他重新部署之前相同的冲突,应该避免。

I Know I always can do: 我知道我总能做到:

git push -f

But I would preffer to avoid the forced push because I work with another person. 但是我会避免与别人一起工作,避免被强迫。 I would like to know what I did wrong. 我想知道我做错了什么。 I thought that was the way. 我以为是这样。

PD. PD。 I have run gitk and it seems there is no reference to the remote origin/hotfix , just the local hotfix appears. 我已经运行了gitk ,似乎没有对远程origin/hotfix引用,只是出现了本地hotfix

Thank you! 谢谢!

Edit: I guess that when I did the rebase the last commit of the branch change to apply the rebase changes, that was the reason why it had another sha1 commit id. 编辑:我猜想当我进行重新基准设置时,分支更改的最后一次提交要应用重新基准更改,这就是它具有另一个sha1提交ID的原因。 I did a pull overriding my local files. 我做了一个覆盖本地文件的请求。

git pull --strategy=ours origin hotfix

One thing you need to know about rebase is: 关于变基,您需要了解的一件事是:

Git will change the SHA hashes of every commit not part of the new base branch. Git将更改不属于新基础分支的每个提交的SHA哈希。

This means there will always be a conflict with the upstream branch after you rebase your local branch and the only way around it is to force push to your upstream. 这意味着在对本地分支重新设置基准之后,上游分支将始终存在冲突,并且绕过它的唯一方法是强制推送到上游分支。

A common practice is to not rebase commits that have been pushed to upstream. 通常的做法是不对已推送到上游的提交进行重新基准化。 Rebasing is still okay if there is only one person working on a branch. 如果只有一个人在分支上工作,则重新定价仍然可以

In this case, you don't have an option but to do a force push. 在这种情况下,您别无选择,只能进行强制推送。 In the future it is advisable to keep the working branch for you and your collaborator separate and have a mix of rebase and merge strategies to share your work 将来建议您将您的工作分支与您的协作者分开,并采用变基和合并策略以共享您的工作

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

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