英文:
GitHub: Difference between Accept current changes and Incoming changes
问题
问题发生在代码冲突时。
如上面所示的图像,有四个选项:
- 接受传入的更改
- 接受当前更改
- 同时接受更改
- 比较更改
我想知道“接受当前更改”和“接受传入的更改”的区别。
英文:
Problem occurs when codes are conflict.
As you see in image given above that four options are there
- Accept incoming changes
- Accept current changes
- Accept Both changes
- Compare changes
I want to know the difference between Accept Current changes
and Accept Incoming changes
答案1
得分: 145
这取决于导致冲突的操作类型(合并或变基)。在解决Git中的冲突时,通常涉及两组更改:
-
来自您当前分支的更改:通常是您当前正在工作或已检出的分支。在您的解释中,这被描述为“您拥有的内容”或“合并的目标”。
-
来自传入分支的更改:您试图将其合并到当前分支(在合并期间)或尝试应用于另一个分支的分支(在变基期间)。这是“您要合并的内容”或“合并的源”。
现在,在VSCode的冲突解决选项的背景下:
-
接受传入更改:这将丢弃当前分支(“您拥有的内容”)中的冲突更改,并保留传入分支(“您要合并的内容”)中的更改。
-
接受当前更改:这将保留当前分支(“您拥有的内容”)中的冲突更改,并丢弃传入分支(“您要合并的内容”)中的更改。
重要的是要理解,在变基期间,“当前分支”和“传入分支”的角色实际上是相反的。在变基中,您的当前分支正在应用于传入分支的顶部。因此,面对冲突时:
- 在变基期间,“当前更改”将指的是您正在变基的分支(通常是基础分支)。
- 在变基期间,“传入更改”将指的是您试图变基的分支(您试图应用于另一个分支的更改)。
英文:
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:
-
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".
-
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).
答案2
得分: 57
如果这是由于重新基于而引起的冲突,你可以这样想 -
- 你的主分支已经被修复
- 一个特性分支最初是从主分支上的一个旧提交开始的,现在正在从那里转移到主分支上的最新提交(这就是重新基于的核心概念)。
现在,如果你从主分支的角度看 -
-
incoming changes
是那些移动到主分支的更改(即特性分支上的更改),因此使用这个术语。 -
current changes
是已经存在于主分支上的更改(即其他开发人员或你自己在主分支上进行的更改)。
在合并冲突的情况下,正如@VonC所建议的,术语是相反的。
英文:
If it's a conflict due to a rebase, you could always imagine like so -
- Your master branch is fixed
- 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.
答案3
得分: 33
- 你正在一个 特性 分支上
1. git pull origin master
当前更改
你当前 特性 分支上的更改。
即将引入的更改
你正在从 master 分支拉取的更改
2. git pull origin master --rebase
在 rebase 过程中,你的特性分支更改会被应用到已经存在于主分支中的提交之上。
当前更改
主 分支上的更改。
即将引入的更改
特性 分支上的更改。
* 在 rebase 后,你需要强制推送你的分支。使用 --force-with-lease
而不是 --force
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论