如何在冲突的 Git rebase 中获得“他们的”更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8146289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get "their" changes in the middle of conflicting Git rebase?
提问by Ondra ?i?ka
I have conflicting branches, branch2 branched from branch1.
我有冲突的分支,分支 2 从分支 1 分支出来。
Let's say when rebasing branch2
on current branch1
, while resolving conflicts, I decide to take some(not all) of "their" (i.e. branch1
) files as-is.
How do I do that?
假设在branch2
基于 current 时branch1
,在解决冲突的同时,我决定按原样获取一些(不是全部)“他们的”(即branch1
)文件。我怎么做?
I tried:
我试过:
git checkout branch1:foo/bar.java
fatal: reference is not a tree: TS-modules-tmp:foo/bar.java
git checkout refs/heads/branch1:foo/bar.java
fatal: reference is not a tree: refs/heads/TS-modules-tmp:foo/bar.java
回答by iGEL
You want to use:
你想使用:
git checkout --ours foo/bar.java
git add foo/bar.java
If you rebase a branch feature_x
against master
(i.e. running git rebase master
while on branch feature_x
), during rebasing ours
refers to master
and theirs
to feature_x
.
如果衍合分支feature_x
对master
(即运行git rebase master
时的分支feature_x
),垫底期间ours
是指master
与theirs
到feature_x
。
As pointed out in the git-rebase docs:
正如git-rebase 文档中所指出的:
Note that a rebase merge works by replaying each commit from the working branch on top of the branch. Because of this, when a merge conflict happens, the side reported as ours is the so-far rebased series, starting with <upstream>, and theirs is the working branch. In other words, the sides are swapped.
请注意,rebase 合并通过在分支顶部重放来自工作分支的每个提交来工作。因此,当发生合并冲突时,报告为我们的一方是迄今为止重新调整的系列,从 <upstream> 开始,而他们的则是工作分支。换句话说,双方互换。
For further details read this thread.
有关更多详细信息,请阅读此线程。
回答by Adrian Cornish
If you want to pull a particular file from another branch just do
如果您想从另一个分支中提取特定文件,只需执行
git checkout branch1 -- filenamefoo.txt
This will pull a version of the file from one branch into the current tree
这会将文件的一个版本从一个分支拉到当前树中