【问题标题】:git rebase fails: Understanding the state of my repositorygit rebase 失败:了解我的存储库的状态
【发布时间】:2014-03-29 14:38:34
【问题描述】:

other_branch 上重新设置my_branch 时,即:

git rebase other_branch

如果有冲突,我会得到标记

<<<<<<< HEAD
stuff_1
=====
stuff_2
>>>>>>> Some commit message 

Q1 第一个问题:stuff_1 是来自 my_branch 还是来自 other_branch

我还注意到,当这种情况发生时,我的 HEAD 现在指向一些未命名的提交,在我的例子中是 65c47727a2500691233cfed2a2cfe7686b7fb92d(这是 cat .git/HEAD 的输出)

我也明白了:

> git status
rebase in progress; onto e41e19d
You are currently rebasing branch 'my_branch" on 'e41e19d'
...
Unmerged paths:
both added: some_file.sh

Q2虽然我修复了变基,但为什么我的 HEAD 指向一些随机提交?

Q3在这种情况下Unmerged pathsboth added 是什么意思??

【问题讨论】:

    标签: git


    【解决方案1】:

    在变基过程开始时,HEAD 设置为 other_branchThat is documented。然后,other_branch..my_branch 的所有提交被一一重新应用。该迭代过程可能会在某些时候失败,然后您必须解决合并冲突,并在解决冲突后执行git rebase --continue

    对 Q2 的回答:当您解决冲突时,您的 HEAD 指向一个提交,该提交对应于成功应用的 other_branch..my_branch 的最后一次提交。使用git show可以识别,当然它的hash是不同的,因为它的parent是不同的。

    Q1 的答案: stuff_1 来自 HEAD。鉴于我在 Q2 的回答中所说的原因,这意味着它来自 other_branch 的修改版本,其中来自 my_branch 的提交可能已经被应用。

    对 Q3 的回答: 未合并的路径表示仍有未解决的冲突。似乎my_branchother_branch 都添加了一个新文件some_file.sh。有关解决该冲突的方法,请参阅问题“Resolving a 'both added' merge conflict in git?”。解决冲突后(在此处修复 some_file.sh),在修复所有问题后执行 git add some_file.shgit rebase --continuegit-rebase 将提交当前更改,并继续进行变基过程。

    【讨论】:

    • “未合并的路径”表示仍有未解决的冲突。解决冲突后(在此处修复 some_file.sh),在全部修复后执行 git add some_file.shgit rebase --continue
    • 谢谢@lrineau。从概念上讲,为什么在解决冲突之后添加(暂存)文件就足够了?为什么我也不需要提交文件?
    • @user815423426:提交由git rebase --continue完成。
    猜你喜欢
    • 2016-04-14
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多