解决冲突后如何才能完成git rebase

时间:2018-03-07 18:12:41

标签: git git-rebase git-merge-conflict

我只是试图改变我提交到远程存储库的一些更改,并且在解决冲突后无法完成更改。我试着改变如下:

$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Applying: My Commit Message
Using index info to reconstruct a base tree...
M   dir_a/dir_b/dir_c/myfile.py
.git/rebase-apply/patch:51: trailing whitespace.

.git/rebase-apply/patch:56: trailing whitespace.

.git/rebase-apply/patch:128: trailing whitespace.

.git/rebase-apply/patch:141: trailing whitespace.

.git/rebase-apply/patch:145: trailing whitespace.

warning: squelched 3 whitespace errors
warning: 8 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging dir_a/dir_b/dir_c/myfile.py
CONFLICT (content): Merge conflict in dir_a/dir_b/dir_c/myfile.py
error: Failed to merge in the changes.
Patch failed at 0001 My Commit Message
The copy of the patch that failed is found in: .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".

解决冲突后,我上演并提交了我的更改:

$ git add dir_a/dir_b/dir_c/myfile.py
$ git commit dir_a/dir_b/dir_c/myfile.py -m"Fixed rebase conflicts"
[detached HEAD a5a4f3b3e] Fixed rebase conflicts
 1 file changed, 193 insertions(+), 13 deletions(-)

但是当我尝试继续时,它就失败了

$ git rebase --continue
Applying: My Commit Message
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 prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

我已经尝试了很多次。有时会对我所在的分支进行更详细的检查,只是暂存我的冲突解决方案而不是提交它们,并且总是回到同一点。

例如,如果我在继续进行rebase之前中止并且没有提交,我会看到同样的错误:

$ git rebase --abort
$ git status
On branch rebase1
nothing to commit, working tree clean

现在,当我开始重新定位

时,我看到(或相信我做的)相同的结果
$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Applying: My Commit Message
Using index info to reconstruct a base tree...
M   dir_a/dir_b/dir_c/myfile.py

Falling back to patching base and 3-way merge...
Auto-merging dir_a/dir_b/dir_c/myfile.py
CONFLICT (content): Merge conflict in dir_a/dir_b/dir_c/myfile.py

error: Failed to merge in the changes.
Patch failed at 0001 My Commit Message
The copy of the patch that failed is found in: .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".

解决冲突后我addrebase的结果相同:

$ git add dir_a/dir_b/dir_c/myfile.py
$ git rebase --continue
Applying: My Commit Message
Applying: My Commit Message For New Code I want to Rebase
Using index info to reconstruct a base tree...
M   dir_a/dir_b/dir_c/myfile.py
Falling back to patching base and 3-way merge...
Auto-merging dir_a/dir_b/dir_c/myfile.py
CONFLICT (content): My Commit Message
error: Failed to merge in the changes.
Patch failed at 0002 Made changes to pass flake8
The copy of the patch that failed is found in: .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".

成功修改我的更改需要做什么/不做什么?

3 个答案:

答案 0 :(得分:3)

解决rebase冲突时,不应提交更改。完成编辑文件以解决冲突后,添加新的更改(例如git add dir_a/dir_b/dir_c/myfile.py)并使用git rebase --continue完成变基。

答案 1 :(得分:1)

在OSX上,我不得不使用git config --global core.trustctime false

请参阅:Git rebase fails, 'Your local changes to the following files would be overwritten by merge'. No local changes?

答案 2 :(得分:0)

我包括这个答案,因为它解决了我遇到的问题,虽然不是我所说的那个问题。当我第一次尝试rebase时,我add我的更改文件没有committing,但是当我尝试git rebase --continue时没有(我相信)运气。然后,我在执行commit之前尝试git rebase --continue我的更改,但仍未成功。

我的错误在于没有意识到在解决了一系列冲突后,当我再次尝试rebase时,可能会出现新的冲突,这些冲突需要修复。当我修复这些新冲突时,我能够成功rebase