gpt4 book ai didi

Git rebase : conflicts keep blocking progress

转载 作者:IT王子 更新时间:2023-10-29 01:22:17 29 4
gpt4 key购买 nike

我有一个 git 分支(称为 v4),它是昨天才由 master 创建的。 master 有一些变化,我想进入 v4。因此,在 v4 中,我尝试从 master 进行 rebase ,但有一个文件一直在搞砸:一个包含版本号的单行文本文件。此文件是 app/views/common/version.txt,在 rebase 之前包含以下文本:

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".

正是在这一点上,在反复思考之后,我把头从 table 上撞了下来。

这是怎么回事?我究竟做错了什么?谁能帮我弄清楚?

编辑 - 对于 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".

最佳答案

我遇到了类似的 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

创建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(-)

回到master,修改version.txt的内容,这样在rebase的时候就会有conflit。

$ 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 分支并尝试 rebase 。它按计划因 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。他告诉我们:“如果没有什么需要准备的,很可能其他东西已经引入了相同的变化;你可能想跳过这个补丁。”所以我们只是跳过提交,rebase 就成功了。

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

警告:请注意 git rebase --skip 将完全删除 git 尝试 rebase 的提交。在我们的例子中,这应该没问题,因为 git 提示这是一个空提交。如果你认为在 rebase 完成后你丢失了更改,你可以使用 git reflog 在 rebase 之前获取你的存储库的提交 ID,并使用 git reset --hard 让你的 depot 回到那个状态(这是另一个破坏性的操作)。

关于Git rebase : conflicts keep blocking progress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4033009/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com