简体   繁体   English

本地和远程分支已经分道扬镳了?

[英]Local and remote branch has been diverged?

Here is my situation这是我的情况

  1. I checkout from main and make my feature branch “my branch “我从 main 结帐并将我的功能分支设为“我的分支”
  2. I pushed my changes into remote “my branch”我将更改推送到远程“我的分支”
  3. Main got advanced with few merges from other people Main 得到了先进,其他人的合并很少
  4. Now I have worked more on my local branch , and want to do following现在我在当地的分支机构工作了更多,并想做以下事情
  5. “ take all the changes of remote main , and put my local branch changes in top of them “ “获取远程主目录的所有更改,并将我的本地分支更改放在其中”
  6. I have tried doing git rebase and pull but doing that just overwrite my local files and They are left with errors due to weird mismatch ( from my local and remote ) .我试过做 git rebase 和 pull 但这样做只会覆盖我的本地文件,并且由于奇怪的不匹配(来自我的本地和远程)而留下错误。 Luckily I have staged and committed so no changes are lost幸运的是,我已经上演并提交了,所以没有丢失任何更改

For this, you cannot do a pull.为此,您不能进行拉动。 You did have the right idea though:不过,您确实有正确的想法:

git rebase main git rebase 主要

Then when locally everything is in order, force push ( git push --force ) to overwrite the remote "my branch", telling it that your state (which includes the commits added from main) is the correct one.然后,当本地一切正常时,强制推送( git push --force )覆盖远程“我的分支”,告诉它您的状态(包括从 main 添加的提交)是正确的状态。

Lets say we have master, branch_A (made from master) and branch_B (also made from master).假设我们有 master、branch_A(由 master 制作)和 branch_B(也由 master 制作)。 I am working on branch_A and my friend is working on branch_B.我正在研究branch_A,而我的朋友正在研究branch_B。 My friends work in branch_B was merged to master.我在 branch_B 工作的朋友被合并到 master。 Now I am done and I want to merge my branch to master as well.现在我完成了,我也想将我的分支合并到 master。 The process I would follow is below:我将遵循的过程如下:

  1. git checkout master
  2. git pull (update local master from with remote changes) git pull (使用远程更改更新本地主机)
  3. git checkout branch_A
  4. git rebase master (this will pull in the changes from master and stack your branch commits on top) git rebase master (这将从 master 中提取更改并将您的分支提交堆叠在顶部)
  5. git push origin branch_A -f (need force since you rebased which changes branch HEAD) git push origin branch_A -f (需要强制,因为你改变了分支 HEAD 的基础)

Hope that helps.希望有帮助。

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

相关问题 用远程跟踪分支覆盖本地分支(分支已分支) - Overwrite local branch with remote tracking branch (branches have diverged) 在git rebase之后,我的本地分支和远程分支发生了分歧 - after git rebase my local branch and remote branch have diverged 本地Git分支在交互式rebase之后与原点不同 - Local Git branch has diverged from origin following an interactive rebase Git远程跟踪分支与具有不同SHA的相同提交的本地分支不同 - Git remote tracking branch diverged from local branch with identical commits with different SHAs Gerrit-当前分支和远程分支已经分开 - Gerrit - Current branch and remote branch have diverged 在 GitLab 中,如何将更改推送到与非主分支不同的远程分支? - How in GitLab push changes to a remote branch that has diverged from non-master branch? 如何将尚未合并到master中的远程分支拉到本地分支中? - How to take a pull of a remote branch that has not been merged into master into a local branch? Git分支发散,而没有本地更改 - Git branch diverged while there're no local change Git:丢弃分散的本地分支上的所有更改 - Git: Discard all changes on a diverged local branch 在远程合并了一个拉取请求后,将更改拉到本地分支时为什么会有冲突? - Why are there conflicts when pulling changes to a local branch after a pull request has been merged at the remote?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM