英文:
Git rebase infinite loop with several hundred commits and never up-to-date
问题
我已经在一个功能分支上工作了几个月,最终有了几百次提交。我运行了 git rebase
并经历了几百次冲突解决,最终同步了。然后我再次运行了 git rebase origin/master
,并且又重新开始了,我坚持解决冲突并完成了这个过程。
出于好奇,我尝试了 git rebase origin/master
,并带有 -i "git rebase -i HEAD~211"
,因为我有211次提交要压缩,但它要求我再次进行相同的冲突解决。
有人能否提供一些建议,告诉我我在这里做错了什么?我如何让它说不需要再次 rebase。当我运行 git merge origin/master
时,它建议它是最新的,这就是我希望的 rebase。我不想将我的功能分支推送到主分支,其中有数百次提交的历史记录。有4个文件在冲突解决中不断重复。我有它们的备份。
我一直在执行 git add/rm 文件名
和 git rebase --continue
等操作,但似乎没有尽头。
我是否应该经常像每天都进行 rebase 以避免这种情况?
git rebase master
git rebase origin/master
git rebase -i HEAD~211
git add 文件名
git rm/添加 文件名
git rebase --continue
英文:
I have been working on a feature branch for couple of months and ended up with several hundred commits. I ran git rebase
and went through few hundred resolutions and it finally synced up. I then ran git rebase origin/master
again and it started all over again and I persisted and resolved conflicts and completed the process.
Out of curiosity I tried git rebase origin/master
again with -i "git rebase -i HEAD~211"
as I have 211 commits that I want to squash but it's asking me to go through same process again i.e. resolve all conflicts.
Could someone offer advice what I'm doing wrong here? How can I get to a point where it says rebase not needed. When I run git merge origin/master it suggests its up-to-date and that's what I want for rebase. I don't want to push my feature branch into master with hundreds of commits in history. There are 4 files that keep repeating in the conflict resolutions. I have a backup for them.
I have been doing git add/rm file-name and git rebase --continue etc but its endless.
Should I have been rebasing regularly like everyday to avoid this?
git rebase master
git rebase origin/master
git rebase -i HEAD~211
git add file-name
git rm/add file-name
git rebase --continue
答案1
得分: 2
以下是要翻译的内容:
每次我运行 git rebase,它都会重新开始整个过程,并要求我解决冲突。
这个,以及你说的其他一切,在你不断地对长期存在的分支进行变基时,是完全正常的。你可以通过使用 git rerere
来简化变基冲突解决的路径 - 这就是它的作用。你向它展示一次如何解决冲突,它会记住下一次。
不过,个人而言,我建议进行_反向合并_ - 即将 master
合并到长期存在的分支以保持它的最新状态。一周一次足够了。这样,冲突的可能性要小得多,如果确实有冲突,你只需解决一次,以后就再也不会看到那个冲突了。你最终的PR的结构不会受到实质性的影响。
英文:
> every time i run git rebase it starts the whole process again and asks me to resolve conflicts
That, and everything else you're saying, is completely normal if you keep rebasing a long-lived branch. You can ease the rebase conflict resolution path with git rerere
— that is what it's for. You show it once how to resolve the conflicts and it remembers next time.
Personally, though, I recommend reverse merging — that is, merge master
into the long-lived branch to keep it up to date. Once a week is enough. That way, conflicts are much less likely, and if there is one, you resolve it once and done, you'll never see that one again. The structure of your eventual PR will not be materially affected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论