我有一个git分支(称为v4),它是昨天由master制作的.掌握了一些变化,我想进入v4.因此,在第4版中,我尝试从master执行rebase,并且一个文件不断搞砸:一行文本文件,其中包含版本号.此文件是app/views/common/version.txt,在变基之前包含此文本:
v1.4-alpha-02
Run Code Online (Sandbox Code Playgroud)
这是我正在做的事情:
> 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".
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
所以,我整理一下,现在看起来像这样:
v1.4-alpha-02
Run Code Online (Sandbox Code Playgroud)
然后我试着继续:首先我尝试提交:
> git commit -a -m "merged"
# Not currently on any branch.
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)
那里没有运气.所以,我试图添加文件:
git add app/views/common/version.txt
Run Code Online (Sandbox Code Playgroud)
没有反应.我想,没有消息是好消息.所以,我试着继续:
> 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".
Run Code Online (Sandbox Code Playgroud)
正是在这一点上,经过这个循环,我正在敲打桌子.
这里发生了什么?我究竟做错了什么?谁能让我直截了当?
编辑 - 为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".
Run Code Online (Sandbox Code Playgroud)
Syl*_*sne 102
我遇到了与rebase类似的问题.我的问题是因为我的一个提交只更改了一个文件,并且在解析时,我放弃了此提交中引入的更改.我能够通过跳过相应的commit(git rebase --skip)来解决我的问题.
您可以在测试存储库中重现此问题.首先创建存储库.
$ mkdir failing-merge
$ cd failing-merge
$ git init
Initialized empty Git repository in $HOME/failing-merge/.git/
Run Code Online (Sandbox Code Playgroud)
然后提交version.txtmaster中的原始内容.
$ 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
Run Code Online (Sandbox Code Playgroud)
创建v4分支并更改内容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(-)
Run Code Online (Sandbox Code Playgroud)
返回master并更改内容,version.txt以便在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(-)
Run Code Online (Sandbox Code Playgroud)
切换回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
Run Code Online (Sandbox Code Playgroud)
我们通过选择master内容来解决冲突version.txt.我们添加文件并尝试继续我们的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".
Run Code Online (Sandbox Code Playgroud)
它失败 !让我们看看git我们的存储库中有哪些变化.
$ git status
# Not currently on any branch.
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)
啊啊,没有变化.如果您详细阅读了上一条错误消息,请git告知我们并建议使用git rebase --skip.他告诉我们"如果没有任何东西可以上台,很可能其他东西已经引入了相同的变化;你可能想跳过这个补丁." 所以我们只是跳过提交并且rebase成功.
$ git rebase --skip
HEAD is now at 7313eb3 master
Run Code Online (Sandbox Code Playgroud)
注意事项:请注意,git rebase --skip将完全删除git尝试重新绑定的提交.在我们的例子中,这应该没问题,因为git抱怨这是一个空提交.如果您认为在rebase完成后丢失了更改,您可以使用git reflog在rebase之前获取存储库的提交ID,并用于git reset --hard使您的depot恢复到该状态(这是另一种破坏性操作).
Bij*_*lle 22
引自这里:http://wholemeal.co.nz/node/9
咦?!?不,我没有忘记使用git add,我做了...就像... 2秒前!
事实证明,因为补丁git没有变化,怀疑出现了问题.Git希望应用补丁,但文件保持不变.
错误消息不是很直观,但确实包含答案.我们只需要告诉rebase跳过这个补丁.也没有必要在文件中修复冲突标记.您将最终获得您正在重新定位的分支的文件版本.
$ git rebase --skip
Run Code Online (Sandbox Code Playgroud)
将app/views/common/version.txt更改为
v1.4-alpha-01
Run Code Online (Sandbox Code Playgroud)
在rebase的这一点上,请记住您正在解决合并冲突以显示非主分支的进展.
所以,在改变
A---B---C topic
/
D---E---F---G master
Run Code Online (Sandbox Code Playgroud)
至
A*--B*--C* topic
/
D---E---F---G master
Run Code Online (Sandbox Code Playgroud)
您正在解决的冲突是如何在主题分支上创建A*.
所以在做完之后git rebase --abort,命令应该是
git checkout topic
git rebase master
< make edits to resolve conflicts >
git add .
git rebase --continue
Run Code Online (Sandbox Code Playgroud)
该错误消息是您的结果git commit -a -m "merged".如果你只是修复了该文件,然后运行git add <file>,并且git rebase --continue,它应该工作的罚款.git rebase --continue正在尝试进行提交,但发现没有挂起的更改要提交(因为您已经提交了它们).