git rebase --fork-point master是什么意思? [英] What does `git rebase --fork-point master` mean?

查看:80
本文介绍了git rebase --fork-point master是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例是在发布功能之前在功能分支中更改提交,例如,重新编写提交消息,压缩某些提交等.我不想将提交移动到一个新的基地.

My use case is changing my commits in a feature branch before I publish it, e.g., reword commit messages, squash some commits, etc. I do not want to move the commits to a new base.

为此,我通常会执行以下操作:

For this, I usually do something like this:

git rebase -i HEAD~4

其中的数字"4"是在我的功能分支中手动计算提交次数的结果.

where the number "4" is the result of manually counting the commits in my feature branch.

我想知道Git是否有一个像这样的命令:为功能分支中的所有提交启动交互式变基,但是不要移动到新的 master 上,而只是呆在原地".我找到了 git rebase -fork-point 选项,并尝试了以下方法:

I was wondering if Git has a command like "start interactive rebase for all commits in my feature branch but don't move then to a newer master – just stay where you are". I found the --fork-point option of git rebase and tried this:

git rebase -i --fork-point master

但是,这没有任何明显的效果,其行为与 git rebase -i master 相同.

However, this doesn't have any noticeable effect and behaves the same as git rebase -i master.

相反,这满足了我的需求:

Instead, this does what I need:

git rebase -i $(git merge-base --fork-point master)

我阅读了 git rebase 文档中的-fork-point 的文档,但不太了解为什么它没有达到我的预期结果.有人可以解释一下吗?

I read the docs of --fork-point in git rebase docs but don't quite understand why it didn't lead to my expected result. Can someone explain it please?

推荐答案

它并没有导致您预期的结果,因为-fork-point 与确定新的基础无关提交[1].

It didn't lead to your expected result because --fork-point has nothing to do with deciding the base for the new commits[1].

因此,默认设置是将新提交基于上游(在这种情况下为 master ),而-fork-point 不会对此产生影响.

So the default is to base the new commits at the upstream (master in this case), and --fork-point doesn't affect that.

(作为参考,-fork-point 的作用是,它使用引用日志细化了猜测"应该重写的提交的计算.这并不总是-或在我看来经验,甚至经常-非常有用.)

(For reference, what --fork-point does is, it uses the reflogs to refine the calculation that "guesses" what commits should be rewritten. This is not always - or, in my experience, even often - very useful.)

您的两个选择是使用合并基准作为上游(如您所述)或使用-onto 选项显式设置新基准(在这种情况下,将其设置为与原始基础).

Your two options are to use the merge base as the upstream - as you describe - or use the --onto option to explicitly set the new base (in this case, setting it to match the original base).

[1]-请记住,即使从概念上来说,您正在编辑提交,但真正的变基总是会写入新的提交-除非什么都不做.因此,当它编辑"提交时,它实际上会创建类似于旧提交但已编辑的新提交.

[1] - remember that even though conceptually you're editing commits, really rebase always writes new commits - except when it does nothing. So when it 'edits' a commit, it really creates new commits that are similar to old commits, but edited.

这篇关于git rebase --fork-point master是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆