简体   繁体   English

使用git rebase,我是否应该假装在解决冲突时未发生某些事情?

[英]With git rebase, should I pretend that certain things didn't happen when resolving conflicts?

I'm new to git and I'm a bit confused about the "right" way of using git rebase. 我是git的新手,对于使用git rebase的“正确”方法有些困惑。

Is the idea that, once I finish the rebase and conflict resolution process, my history will look as if I didn't change my mind along the way? 是这样的想法吗:一旦我完成了改组和解决冲突的过程,我的历史就好像没有一路改变主意一样?

Let's say, for instance, that I have commit A and commit B. Commit A makes some important changes but also introduces a function that I later remove in commit B. When rebasing, I encounter a conflict from the function introduced in commit A. 例如,假设我有一个提交A和一个提交B。提交A进行了一些重要的更改,但还引入了一个功能,后来我在提交B中将其删除。重新定级时,我遇到了与提交A中引入的功能冲突的情况。

What is the "right" way to respond here? 在这里做出回应的“正确”方法是什么? Should I edit commit A to avoid introducing the function altogether and then skip commit B entirely? 我是否应该编辑提交A以避免完全引入功能,然后完全跳过提交B? If so, don't I miss out on important context about the evolution of the code? 如果是这样,我是否会错过有关代码演变的重要背景信息?

I am assuming that you rebase commit B onto commit A. 我假设您将提交B重新设置为提交A。

If there are conflicts, don't change commit A since that represents code changes before commit B. Instead change commit B (the edits later in the history) to eliminate the conflict and to fix any bugs. 如果存在冲突,请不要更改提交A,因为这表示提交B之前的代码更改。相反,请更改提交B(历史记录的后面的编辑内容),以消除冲突并修复所有错误。

Generally, you can use merge or rebase as you like. 通常,您可以根据需要使用merge或rebase。 If you are the only person on your git project, it doesn't matter. 如果您是git项目中的唯一人员,那没关系。 Larger groups might have a preference. 较大的群体可能会有偏好。 Some like rebase perhaps so it seems like everything is linear. 有人喜欢重新设定基准,因此似乎一切都是线性的。 Others prefer merge because it matches what really happened more. 其他人则更喜欢合并,因为它与实际发生的事情相匹配。

Larger projects also might like to squeeze a branch into a single commit (with interactive rebase) before merging it back into the master branch (perhaps to simplify history). 较大的项目也可能希望将分支压缩到单个提交中(使用交互式rebase),然后再将其合并回master分支(可能是简化历史记录)。

In my opinion, it shouldn't matter. 我认为这无关紧要。 When you rebase commits it is usually because you have completed some peice of functionality or reached some sort of milestone and want to "rewrite" the history. 对提交进行重新设置基准时,通常是因为您已完成一些功能或达到某种里程碑,并且想要“重写”历史记录。 In essence, you are more interested on a high level overview of what you did rather than going into detail. 从本质上讲,您更想对所做的工作进行高层次的概述,而不是进行详细介绍。

If you want to highlight specific code changes as part of the rebase then put them in the commit message. 如果要突出显示特定的代码更改作为重新设置的一部分,则将它们放入提交消息中。

"if so, don't I miss out on important context about the evolution of the code" “如果是这样,我是否会错过有关代码演变的重要背景信息”

Well yes, but that's the point of a rebase. 是的,但这就是重新设置基准的重点。 A rebase rewrites history to how you wish it had been :-) 重新建立基础将历史记录重写为您希望的样子:-)

You don't mention above where your commits are, on the same branch being rebaseed with an interactive rebase or in separate branches. 您在上面没有提到提交的位置,在同一分支上使用交互式rebase进行了重新设置,还是在单独的分支中。

I'll assume separate branches, the point of doing a rebase is that you are reordering the commits on one branch to be appended to the end of the other branch, if a conflict now occurs then you need to amend the commit as if it had been coded after the other commit, if that means a function doesn't see the light of day, then so be it. 我假设使用单独的分支,进行重新基准的目的是要对一个分支上的提交进行重新排序,以将其追加到另一分支的末尾,如果现在发生冲突,则需要修改提交,就像在另一个提交之后被编码,如果那意味着一个函数看不到日光,那就照做吧。

If the temporal order of the commits is important to you for context, merge instead. 如果提交的时间顺序对上下文很重要,请合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解决git rebase期间的冲突 - Resolving conflicts during git rebase 在解决冲突时,我如何判断 git 变基的距离? - How can I tell how far into a git rebase I am when resolving conflicts? 解决git rebase冲突时进行提交,无法继续 - Made commit while resolving git rebase conflicts, can't continue Git-基于一个提交而不解决冲突 - Git - rebase to one commit without resolving conflicts 解决了重新设置分支机构的所有冲突后,我执行了“ git rebase --continue”,并且得到了“是否没有进行重新设置?”。 接下来我该怎么办? - After resolving all conflicts in rebasing my branch, I did “git rebase --continue” and I got “No rebase in progress?” . What should I do next? Git Merge vs Rebase - 解决冲突 - Git Merge vs Rebase - Resolving conflicts 当我应该/不应该使用git pull --rebase - When i should/shouldn't use git pull --rebase 当我没有做出任何改变时,如何在git交互式rebase中发生冲突? - How can there be conflicts in a git interactive rebase when I haven't made any changes? 在变基期间,如何让 Git 始终使用“他们的/我们的”来解决特定文件中的冲突? - How do I make Git always use "theirs/ours" for resolving conflicts in a particular file, during rebase? git rebase-我挤压没有删除提交 - Git rebase - i squashing didn't remove commit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM