[Git] Current Change 和 Incoming Change 究竟哪个是新来的

1,697 阅读1分钟

在使用VS Code 管理代码仓库时, 我们经常需要解决一个git的问题, 那就是如果需要conflict的merge, 我们就需要Resolve in Merge Editor,

image.png

image.png

那么我们往往会陷入一个confusion, Current Change 和 Incoming Change 究竟哪个是新来的?

于是就有下面这个解释StackOverflow from VonC

It depends on the type of operation (merge or rebase) leading to that conflict.
When you are trying to resolve conflicts in Git, you are typically dealing with two sets of changes:

  1. Changes from your Current Branch: Often the branch you are currently working on or have checked out. In your explanation, this is described as "what you have" or "the destination of the merge".
  2. Changes from the Incoming Branch: The branch you are trying to merge into your current branch (during a merge) or the branch you are attempting to apply on top of another branch (during a rebase). This is "what you merge" or "the source of the merge".

Now, in the context of the conflict resolution options in VSCode:

  • Accept Incoming changes: That will discard the conflicting changes from your current branch ("what you have") and keep the changes from the incoming branch ("what you merge").
  • Accept current changes: That will keep the conflicting changes from your current branch ("what you have") and discard the changes from the incoming branch ("what you merge").

It is important to understand that during a rebase, the roles of "current branch" and "incoming branch" are essentially reversed. In a rebase, your current branch is being applied on top of the incoming branch. So, when faced with conflicts:

  • "Current changes" during a rebase will refer to the branch onto which you are rebasing (usually the base branch).
  • "Incoming changes" during a rebase will refer to the branch that you are trying to rebase (the changes you are attempting to apply on top of another branch).

所以结果很清晰了, 我们要接收的是Incoming Branch.