Git:在master上进行rebase时不应用本地分支更改

时间:2016-04-18 07:22:10

标签: git git-rebase

E.g。我有一个基于<div class="card card--user"> 的{​​{1}}分支,其中包含1个新提交和2个添加文件。

feature

现在我想在master上重新绑定此commit hash1 A test.html A test.png 分支以获取最新代码。自从我开始处理feature分支1后,master中的新提交已添加。

feature

当我执行master时,我得到了这个输出。

commit hash2
A test.html

结果变为git rebase master完全否定,First, rewinding head to replay your work on top of it... Applying: Initial commit. Using index info to reconstruct a base tree... M test.html Falling back to patching base and 3-way merge... error: The following untracked working tree files would be overwritten by merge: test.html Please move or remove them before you can merge. Aborting Failed to merge in the changes. Patch failed at 0001 Initial commit. The copy of the patch that failed is found in: /<path>/.git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort". feature的版本,而test.html根本没有添加。

如何解决这种情况?

2 个答案:

答案 0 :(得分:0)

如消息所示,发生合并冲突,只需手动解决冲突,然后运行git rebase --continue

答案 1 :(得分:0)

由于在master和本地分支上都修改了相同的文件,因此Git无法自动合并它们。您必须自己解决冲突,大多数现代IDE都有办法实现,否则您可以使用kdiff或other tools查找3路差异。

一旦解决了冲突,就必须告诉git继续。 git rebase --continue

至于为什么git没有添加.png文件,从Git manual你可以看到rebase是如何工作的:

  

它通过转到两个分支的共同祖先(你正在使用的那个和你正在重新定位的那个分支)来工作,获得你所在的分支的每个提交所引入的差异,保存那些差异到临时文件,将当前分支重置为与要重新绑定到的分支相同的提交,最后依次应用每个更改。

由于git无法成功将更改应用于您的功能分支,因此会暂停处理以便您采取措施。

相关问题