改善GIT对相邻块的合并冲突的建议?
与我以前的问题有关 git Merge” ?
By default, git's merge algorithm can give dangerous/unhelpful suggestions.
例如,我有时会有情况,我想将本地开发分支的一些代码更改推向主分支,但是将其他更改保留在纯本地(例如,我仍然需要的调试代码,或者未完成的更改被陷入相同的更改分支)。
Say, there is a commit sequence:
! --- devel~2 = master
program main
end program main
! --- devel~1
program main
write *, "Some debug output"
end program main
! --- devel = HEAD
program main
write *, "Some debug output"
write *, "Some release mode output"
end program main
Now I use git rebase -i master
and want to reverse the order of the two changes. Since it affects adjacent hunks, it will create a merge conflict:
program main
<<<<<<< HEAD
=======
program main
write *, "Some debug output"
write *, "Some release mode output"
>>>>>>> b6b1ecc... Add debug message
end program main
It does make sense, as the second line could very well be invalid without the first.但是,如果两个添加是独立的,则GIT提出的两个建议都是不正确的。
At this point, the best thing I can do is do look at
git log -n 1 -U b6b1ecc
which will show me what part of the change is really wanted.但是在现实世界中,通常并不明显, git提出的建议是不正确的,因此我最终将未完成的更改推向了主分支。
有什么方法可以使GIT提供更合适的建议?特别是以这样的方式,Devel分支中文件的最终状态保持不变。
Related to my previous question Git merge conflict upon rebasing adjacent deletion and insertion?
By default, git's merge algorithm can give dangerous/unhelpful suggestions.
For instance, I have sometimes situations, where I want to push some code changes of my local development branch to the master branch, but keep other changes purely local (e.g. debug code that I still need, or unfinished changes that got mangled into the same branch).
Say, there is a commit sequence:
! --- devel~2 = master
program main
end program main
! --- devel~1
program main
write *, "Some debug output"
end program main
! --- devel = HEAD
program main
write *, "Some debug output"
write *, "Some release mode output"
end program main
Now I use git rebase -i master
and want to reverse the order of the two changes. Since it affects adjacent hunks, it will create a merge conflict:
program main
<<<<<<< HEAD
=======
program main
write *, "Some debug output"
write *, "Some release mode output"
>>>>>>> b6b1ecc... Add debug message
end program main
It does make sense, as the second line could very well be invalid without the first. However, if the two additions are independent, both suggestions made by git are incorrect.
At this point, the best thing I can do is do look at
git log -n 1 -U b6b1ecc
which will show me what part of the change is really wanted. But in real-world scenarios, it typically isn't even obvious, that the suggestion made by git is incorrect and I've ended up pushing an unfinished change to the master branch because of it.
Is there any way to make git give more appropriate merge suggestions? Especially in such a way, that the final state of the file in the devel branch remains unchanged by the rebase.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论