Git rebase: 冲突继续阻碍进程

我有一个 git 分支(称为 v4) ,它是昨天由 master 制作的。主版本有一些变化,我想进入 V4。因此,在 v4中,我尝试从 master 进行一个 rebase 操作,有一个文件总是把事情搞砸: 一个包含版本号的一行文本文件。这个文件是 app/views/common/version.txt,在重新定基之前包含以下文本:

v1.4-alpha-02

我是这么做的:

> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch


When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

version.txt现在看起来是这样的:

<<<<<<< HEAD:app/views/common/version.txt
v1.4-alpha-02
=======
v1.4-alpha-01
>>>>>>> new version, new branch:app/views/common/version.txt

所以,我整理了一下,现在看起来是这样的:

v1.4-alpha-02

然后我试着继续: 起初我试着承诺:

> git commit -a -m "merged"
# Not currently on any branch.
nothing to commit (working directory clean)

没什么进展,所以,我试着添加文件:

git add app/views/common/version.txt

没有回应。没有消息就是好消息,我想。所以,我试着继续:

> git rebase --continue
Applying: new version, new branch
No changes - did you forget to use 'git add'?


When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

It's at this point, after going round and round with this, that I'm banging my head off the desk.

这是怎么回事? 我做错了什么? 有人能教教我吗?

EDIT - for unutbu

我按照您的建议修改了文件,得到了相同的错误:

> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch


When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
109906 次浏览

将 app/views/common/version. txt 更改为

v1.4-alpha-01

此时在 rebase 中,请记住您正在解决合并冲突,以显示 非主人分支的进展。

所以,从

      A---B---C topic
/
D---E---F---G master

              A*--B*--C* topic
/
D---E---F---G master

the conflict you are resolving is in how to create A* on the topic branch.

因此,在执行 git rebase --abort之后,命令应该是

git checkout topic
git rebase master
< make edits to resolve conflicts >
git add .
git rebase --continue

您所看到的行为不是我所期望的典型的只有这种冲突的 rebase。考虑使用一个单独的分支来进行这个 rebase (特别是如果您已经远程推送了正在快进的提交)。此外,git mergetool还有助于解决冲突和记住发出 git add

在这个最小的示例中,rebase 按预期工作?

#!/bin/bash


cd /tmp
mkdir rebasetest
cd rebasetest
git init
echo 'v1.0' > version.txt
git add version.txt
git commit -m 'initial commit'
git checkout -b v4
echo 'v1.4-alpha-01' > version.txt
git add version.txt
git commit -m 'created v4'
git checkout master
git merge v4
echo 'v1.4-alpha-01-rc1' > version.txt
git add version.txt
git commit -m 'upped version on master to v1.4-alpha-01-rc1'
git checkout v4
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git commit -m 'starting work on alpha-02'


git rebase master
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git rebase --continue

Here are some ideas:

引自: http://wholemeal.co.nz/node/9

Huh?!? No, I didn't forget to use git 加上,我做到了... 大概... 2秒 之前!

事实证明,因为没有 从补丁 git 嫌疑人改变 出了点问题 Git 期待着 应用的补丁,但是 文件保持不变。

错误消息不是很清楚 直观,但它确实包含 回答,我们只需要告诉 rebase 跳过这个补丁,也不是 修复冲突标记的必要性 在文件中。你将结束与 文件版本 基于。

$ git rebase --skip

我在使用 rebase 时遇到了类似的问题。我的问题是因为我的一个提交只更改了一个文件,并且在解析时,我丢弃了在这个提交中引入的更改。我能够通过跳过相应的提交(git rebase --skip)来解决我的问题。

您可以在测试存储库中重现这个问题。

$ mkdir failing-merge
$ cd failing-merge
$ git init
Initialized empty Git repository in $HOME/failing-merge/.git/

然后在 master 中提交 version.txt的原始内容。

$ echo v1.4-alpha-02 > version.txt
$ git add version.txt
$ git commit -m initial
[master (root-commit) 2eef0a5] initial
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 version.txt

Create the v4 branch and change the content of version.txt.

$ git checkout -b v4
Switched to a new branch 'v4'
$ echo v1.4-alpha-03 > version.txt
$ git add version.txt
$ git commit -m v4
[v4 1ef8c9b] v4
1 files changed, 1 insertions(+), 1 deletions(-)

返回到 master并更改 version.txt的内容,以便在重建基础期间出现冲突。

$ git checkout master
Switched to branch 'master'
$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git commit -m master
[master 7313eb3] master
1 files changed, 1 insertions(+), 1 deletions(-)

切换回 v4分支并尝试重新定位。它失败了,按计划在 version.txt中发生冲突。

$ git checkout v4
Switched to branch 'v4'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: v4
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging version.txt
CONFLICT (content): Merge conflict in version.txt
Recorded preimage for 'version.txt'
Failed to merge in the changes.
Patch failed at 0001 v4


When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
$ cat version.txt
<<<<<<< HEAD
v1.4-alpha-04
=======
v1.4-alpha-03
>>>>>>> v4

我们通过选择 version.txtmaster内容来解决这个冲突。我们添加该文件并尝试继续我们的 rebase。

$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git rebase --continue
Applying: v4
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.


When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

它失败了! 让我们看看 git认为我们的存储库中有哪些更改。

$ git status
# Not currently on any branch.
nothing to commit (working directory clean)

啊啊,没有变化。如果您详细阅读了前面的错误消息,git会通知我们这一点,并建议使用 git rebase --skip。他告诉我们: “如果没有什么可以做的了,那么很有可能其他的东西已经引入了相同的更改; 您可能想要跳过这个补丁。”所以我们只要跳过提交,重建就成功了。

$ git rebase --skip
HEAD is now at 7313eb3 master

Word of caution: Please note that git rebase --skip will completely drop the commit that git tried to rebase. In our case, this should be okay since git is complaining this is an empty commit. If you think you've lost changes once the rebase is complete, you can use git reflog to get the commit id of your repository before the rebase, and use git reset --hard to get your depot back in that state (this is another destructive operation).

该错误消息是 git commit -a -m "merged"的结果。如果您只是修复了文件,然后运行 git add <file>git rebase --continue,它应该可以正常工作。git rebase --continue正在尝试执行提交,但发现没有要提交的挂起的更改(因为您已经提交了这些更改)。