Git rebase:冲突会阻止进度 [英] Git rebase: conflicts keep blocking progress
问题描述
我有一个git分支(称为v4),它是由昨天的主人制作的。主人有一些变化,我想进入v4。因此,在第4版中,我试图从master中做一个rebase,并且有一个文件不断搞砸:一行文本文件,它包含版本号。这个文件是 app / views / common / version.txt
,它在重新包装之前包含这段文字:
v1.4-alpha-02
以下是我正在做的事情:
> git rebase master
首先,倒带头重播你的作品...
应用:新版本,新分支
错误:补丁失败:app / views / common / version。 txt:1
错误:app / views / common / version.txt:修补程序不适用
使用索引信息重新构建基础树...
回退到修补基础和3-合并...
自动合并app / views / common / version.txt
CONFLICT(内容):合并app / views / common / version.txt中的冲突
合并失败变化。
补丁失败,为0001新版本,新分支
当你解决这个问题时,运行git rebase --continue。
如果您希望跳过此修补程序,请运行git rebase --skip。
要恢复原始分支并停止重新分配运行git rebase --abort。
现在
< <<<<<<< HEAD:app / views / common / version.txt
v1.4-alpha-02
=======
v1.4-alpha-01
> >>>>>>新版本,新分支:app / views / common / version.txt
所以,我整理一下现在看起来像这样:
v1.4-alpha-02
然后我尝试继续:首先我尝试一次提交:
> git commit -a -m合并
#当前不在任何分支上。
没有提交(工作目录干净)
没有运气。因此,我试图添加文件:
$ p $ g $ git add app / views / common / version.txt
没有回应。我想,没有消息是好消息。所以,我试着继续:
> git rebase --continue
应用:新版本,新分支
没有变化 - 你忘了使用'git add'吗?
当你解决这个问题时,运行git rebase --continue。
如果您希望跳过此修补程序,请运行git rebase --skip。
要恢复原始分支并停止重新分配运行git rebase --abort。
在这个过程中,在这个过程中,我正在甩掉我的头办公桌。
这是怎么回事?我究竟做错了什么?任何人都可以设置我的直线?
编辑 - 为unutbu
我改变了文件,同样的错误:
> git rebase master
首先,倒带头重播你的作品...
应用:新版本,新分支
错误:补丁失败:app / views / common / version。 txt:1
错误:app / views / common / version.txt:修补程序不适用
使用索引信息重新构建基础树...
回退到修补基础和3-合并...
自动合并app / views / common / version.txt
CONFLICT(内容):合并app / views / common / version.txt中的冲突
合并失败变化。
补丁失败,为0001新版本,新分支
当你解决这个问题时,运行git rebase --continue。
如果您希望跳过此修补程序,请运行git rebase --skip。
要恢复原始分支并停止重新分配运行git rebase --abort。
我遇到了与rebase类似的问题。我的问题是由于我的某个提交只改变了一个文件而引起的,在解析时,我放弃了在此提交中引入的更改。我可以跳过相应的提交( git rebase --skip
)来解决我的问题。
您可以在测试存储库中重现此问题。首先创建仓库。
$ mkdir失败合并
$ cd失败合并
$ git init
在$ HOME / failing-merge / .git /
中初始化的空Git仓库
在master中原始内容 version.txt
。
$ b
$ echo v1 .4-alpha-02> version.txt
$ git add version.txt
$ git commit -m initial
[master(root-commit)2eef0a5] initial
1个文件已更改,1个插入(+) ,0删除( - )
创建模式100644 version.txt
创建 v4
分支并更改 version.txt
的内容。
$ git checkout -b v4
切换到新分支'v4'
$ echo v1.4-alpha-03> version.txt
$ git add version.txt
$ git commit -m v4
[v4 1ef8c9b] v4
1个文件已更改,1个插入(+),1个删除( - )
回到 master
并更改 version.txt
的内容,这样在rebase期间会有一个conflit。
$ git checkout master
转换到分支'master'
$ echo v1.4-alpha-04> version.txt
$ git add version.txt
$ git commit -m master $ b $ [master 7313eb3] master
1个文件已更改,1个插入(+),1个删除( - )
切换回 v4
分支并尝试改变。它按照计划在 version.txt
中遇到了麻烦。
$ git checkout v4
转换到分支'v4'
$ git rebase master
首先,倒带头重播你的作品......
应用:v4
使用索引信息重建基础树...
回退到修补基础和3路合并...
自动合并version.txt
CONFLICT(内容):合并冲突in version.txt
'version.txt'记录的原始图像
在变更中未合并。
补丁失败,为0001 v4
当你解决这个问题时,运行git rebase --continue。
如果您希望跳过此修补程序,请运行git rebase --skip。
要恢复原始分支并停止重新分配运行git rebase --abort。
$ cat version.txt
<<<<<<<<< HEAD
v1.4-alpha-04
=======
v1.4-alpha-03
>>>>>> > v4
我们通过选择 master
version.txt
的内容。我们添加文件并尝试继续我们的rebase。
$ echo v1.4-alpha-04> version.txt
$ git add version.txt
$ git rebase --continue
应用:v4
没有变化 - 你忘了使用'git add'吗?
如果没有剩下任何东西,那么有可能是其他
已经引入了相同的变化;你可能想跳过这个补丁。
当你解决这个问题时,运行git rebase --continue。
如果您希望跳过此修补程序,请运行git rebase --skip。
要恢复原始分支并停止重新分配运行git rebase --abort。
失败!让我们看看 git
认为存在于我们的仓库中。
$ git status
#目前没有任何分支。
什么都没有提交(工作目录干净)
<啊>,没有变化。如果您详细阅读了以前的错误消息, git
通知我们这一点,并建议使用 git rebase --skip
。他告诉我们:如果没有什么可以继续的话,那么其他的东西可能已经引入了相同的变化;你可能想要跳过这个补丁。所以我们只是跳过提交并且rebase成功。
$ git rebase --skip
HEAD现在在7313eb3 master
警告字:请注意, git rebase --skip
会完全放弃 git
尝试重新绑定的提交。在我们的例子中,这应该是可以的,因为 git
在抱怨这是一个空的提交。如果您认为在完成rebase之后失去了更改,则可以使用 git reflog
在rebase之前获取存储库的提交ID,并使用 git reset --hard
让你的软件仓库回到这种状态(这是另一个破坏性的操作)。
I have a git branch (called v4), that was made from master just yesterday. There were a couple of changes to master, that I want to get into v4. So, in v4, I tried to do a rebase from master, and one file keeps screwing things up: a one-line text file, that contains the version number. This file is app/views/common/version.txt
, which before rebasing contains this text:
v1.4-alpha-02
Here's what I'm doing:
> 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".
The version.txt
now looks like this:
<<<<<<< HEAD:app/views/common/version.txt
v1.4-alpha-02
=======
v1.4-alpha-01
>>>>>>> new version, new branch:app/views/common/version.txt
So, I tidy it up and it looks like this now:
v1.4-alpha-02
and then I tried to carry on: at first I try a commit:
> git commit -a -m "merged"
# Not currently on any branch.
nothing to commit (working directory clean)
No luck there. So, I was trying to add the file:
git add app/views/common/version.txt
No response. No news is good news, I guess. So, I try to continue:
> 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.
What's going on here? What am I doing wrong? Can anyone set me straight?
EDIT - for unutbu
I changed the file as you suggested and get the same error:
> 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".
I encountered a similar problem with a rebase. My problem was caused because one of my commit only changed a file, and when resolving, I discarded the change introduced in this commit. I was able to solve my problem by skipping the corresponding commit (git rebase --skip
).
You can reproduce this problem in a test repository. First create the repository.
$ mkdir failing-merge
$ cd failing-merge
$ git init
Initialized empty Git repository in $HOME/failing-merge/.git/
Then commit the original content of version.txt
in master.
$ 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(-)
Go back to master
and change the content of version.txt
so that there will be a conflit during the rebase.
$ 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(-)
Switch back to v4
branch and try to rebase. It fails with a conflit in version.txt
as planned.
$ 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
We resolve the conflict by selecting the master
content of version.txt
. We add the file and try to continue our 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".
It fails ! Let's see what changes git
think there is in our repository.
$ git status
# Not currently on any branch.
nothing to commit (working directory clean)
Ah ah, there is no change. If you read in detail the previous error message, git
informed us of this and recommended to use git rebase --skip
. He told us "If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this patch." So we just skip the commit and the rebase succeed.
$ 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 rebase:冲突会阻止进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!