你的分支和 ‘origin/test-A’ 已经分叉,分别有5个和21个不同的提交。

huangapple go评论99阅读模式
英文:

Your branch and 'origin/test-A' have diverged, and have 5 and 21 different commits each, respectively

问题

I am currently on branch Test-A. On doing git status on the terminal, I get the following message:

On branch Test-A <br>
Your branch and &#39;origin/Test-A&#39; have diverged,
and have 5 and 21 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

I created a Merge Request from Test-A to Test-B branch. After the changes got merged. I started getting that message.

Problem Statement: I am wondering how I can fix this.

英文:

I am currently on branch Test-A. On doing git status on the terminal, I get the following message:

On branch Test-A <br>
Your branch and &#39;origin/Test-A&#39; have diverged,
and have 5 and 21 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

I created a Merge Request from Test-A to Test-B branch. After the changes got merged. I started getting that message.

Problem Statement: I am wondering how I can fix this

答案1

得分: 1

你的 Git 仓库有两种分支。本地分支仅存在于你的仓库中,而远程分支可以被所有人查看(这些通常以 origin/ 为标识)。它们通常具有相同的名称以方便使用,但这不是必需的。

本地分支可以设置为跟踪远程分支。这允许你运行 git pushgit pull 来发送和接收来自 origin 的更新。

你所看到的消息是本地分支和它正在跟踪的远程分支之间的差异,即每个分支上的提交。这种情况通常发生在你正在本地分支上进行工作并进行一些提交的同时,其他人将新的提交推送到远程分支。在你的工作过程中,你运行了 git fetch 或者如果在另一个分支上运行了 git pull,Git 将更新远程分支的最后一个提交的状态,并发现它有一些你的本地版本没有的提交。

正如消息所说,运行 git pull 将会更新这一差异(它可能会导致发生合并提交,我更喜欢使用 git pull --rebase 来避免这种情况发生)。

英文:

Your git repository has 2 kinds of branches. Your local branches that only exist in your repository and remote branches which can be viewed by everyone (these are identified origin/). These usually have the same name for ease of use but don't need to

A local branch can be set to track a remote branch. This allows you run git push and git pull to send and receive updates with origin.

The message that you are seeing is the local branch and the remote branch that it is tracking each of commits that the other does not have. A common way that this would happen is you are doing work on your branch and make some commits. Meanwhile, someone else pushes new commits to the remote branch. In the course of your work, you run git fetch or if on another branch git pull, git will update the status of the last commit that the remote branch is at and find that it has commits that your local version does not have.

As the message says, running git pull will update this (it can cause a merge commit to happen, I prefer git pull --rebase to avoid this).

答案2

得分: 0

TL;DR这种情况可以通过合并或变基来解决(我分享Schleis的观点,即变基是明显更好的选择)。

然而,为了回答一些潜在问题并扩展Schleis的答案,我将添加一些更多信息。

首先,你应该从今天开始将gitk --all作为你的日常版本历史可视化工具。

是的,界面可能看起来不太现代,但自从2005年开始使用git以来,我还没有找到任何能够替代它的替代品。

因此,让我给出一个测试存储库的示例屏幕截图,大致描述了你当前的情况(我没有费心创建所有21个不同的提交,只有13个)。

你的分支和 ‘origin/test-A’ 已经分叉,分别有5个和21个不同的提交。

结合有关远程和本地分支之间差异的信息,看看这个截图如何非常清楚地解释了你有一些本地更改,超出了与远程分支的最后共享历史的情况,以及远程Test-A分支有一些新的提交,你的分支还没有合并?

我不会详细讨论合并/变基,只是展示各自的结果会是什么样子:

你的分支和 ‘origin/test-A’ 已经分叉,分别有5个和21个不同的提交。

即使没有先前的知识,仅仅查看gitk的输出就能立即解释差异。

每个使用git的人真的都应该每天都查看gitk

1
实际上,你想要使用gitk "--exclude=refs/notes/*" --all &来排除来自git-test的缓存测试结果,因为你总是使用它来测试和验证你分支上的所有提交,对吗?对不对?如果没有,你真的应该!

英文:

> I am wondering how I can fix this

TL;DR this situation is resolved either with a merge or a rebase (and I share Schleis' view that rebase is the clearly better choice).


However to address some of the underlying question and to expand on Schleis' answer I'll add a bit more.

First you should start using gitk --all<sup>1</sup> as your every-day version history visualization tool from today and the rest of your life.

Yes, the ui might not look modern but since starting with git in 2005 I have yet not found any alternative that is remotely close to be able to replace it.

So to give an example screenshot from a test repo that approximately describes your current situation (I did not bother to create all 21 commits in difference, only 13).

你的分支和 ‘origin/test-A’ 已经分叉,分别有5个和21个不同的提交。

Together with the information about the difference between remote and local branches, see how this screenshot super clearly explains the situation that you have some local changes that is ahead of the last common shared history with the remote branch, and likewise that the remote Test-A branch has some newer commits that your branch has not incorporated yet?


I am not going into details on merge/rebase just show how the respective results would look like:

你的分支和 ‘origin/test-A’ 已经分叉,分别有5个和21个不同的提交。

Even without no prior knowledge just looking at gitk output pretty much explains the difference immediately.

Everyone using git really ought to look at gitk every single day.


<sup>1</sup>
Actually you want gitk &quot;--exclude=refs/notes/*&quot; --all &amp; to exclude cached test results from git-test, because you always use it to test and verify all your commits on a branch, right? Right? If not you really, really, really, really should!

huangapple
  • 本文由 发表于 2023年4月4日 04:13:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75923419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定