GitHub: 接受当前更改和传入更改之间的区别

当代码发生冲突时就会出现问题。

VSCode merge resolution

如上图所示,有四个选项

  1. 接受传入的更改
  2. 接受当前的变化
  3. 接受两个变更
  4. 比较变化

我想知道 Accept Current changesAccept Incoming changes之间的区别

94770 次浏览

It depends on the type of operation (merge or rebase) leading to that conflict.

In your case, a merge, where:

  • current change represents what you have (the destination of the merge)
  • incoming change represents what you merge (the source of the merge)

Then:

  • Option 1 ("Accept Incoming changes") would ignore completely what you had, and keep what you merge.
  • Option 2 ("Accept current changes") would ignore completely what you merge, and keep what you had.

Don't forget, in case of a rebase, "what you have" and "what you merge" are reversed.

If it's a conflict due to a rebase, you could always imagine like so -

  1. Your master branch is fixed
  2. A feature branch that originated from an older commit on master, is shifting itself from there to the latest commit on master (that's what a rebase is, at its core).

Now, if you see from the point of view of master -

  • incoming changes are the ones that move to master (i.e. changes in your feature branch), hence the term.

  • current changes are the ones that are already present in master (i.e. ones done by fellow developers or yourself on master).

In case of merge conflicts, as suggested by @VonC, the terminology is reversed.

You are on a feature branch

1. git pull origin master

Current changes

Changes on your current feature branch.

Incoming changes

Changes you are pulling from i.e the master branch


2. git pull origin master --rebase

During rebase your feature branch changes are applied on top of the commits that are already there in master branch.

Current changes

Changes on the master branch.

Incoming changes

Changes on the feature branch.


* After a rebase, you need to force push your branch. Use --force-with-lease instead of --force