Git重新定位可能的错误 [英] Git rebase possible bug
问题描述
我正在使用最新的 git版本2.23.0 ,我想我已经找到了除非我弄错了,否则git rebase中的错误.该错误不在功能上,而在显示消息中.
I am using git version 2.23.0 which is latest for MAC and I think I have found a bug in git rebase unless I am getting it wrong. The bug is not in the functionality but in the display message.
让我们使用以下脚本将git历史记录设为:
Let us use the following script to have our git history as :
#!/bin/bash
git init .
echo "10" >> 1.txt && git add . && git commit -m "1"
# Add 2 commits to master
echo "3" >> 1.txt && git commit -am "m3"
echo "2" >> 1.txt && git commit -am "m2"
#checkout topic branch
git checkout -b topic HEAD~2
echo "1" >> 1.txt && git commit -am "t1"
echo "2" >> 1.txt && git commit -am "t2"
echo "1" >> 1.txt && git commit -am "t3"
echo "2" >> 1.txt && git commit -am "t4"
#checkout small_topic
git checkout -b small_topic HEAD~2
echo "1" >> 1.txt && git commit -am "s1"
echo "2" >> 1.txt && git commit -am "s2"
git checkout topic
git merge small_topic
echo "1" >> 1.txt && git commit -am "t5"
echo "2" >> 1.txt && git commit -am "t6"
#Show graph
git log --oneline --all --decorate --graph
历史记录将如下所示-
* ea3543d (HEAD -> topic) t6
* b57cbbc t5
* 2d5e7d3 Merge branch 'small_topic' into topic
|\
| * c94bb3b (small_topic) s2
| * 7dab544 s1
* | 37ae0d9 t4
* | b667871 t3
|/
* 6486a67 t2
* 490f6d3 t1
| * 84d8343 (master) m2
| * f8c8abc m3
|/
* 3018ae2 1
我们主要有2个分支-master
和topic
. HEAD现在指向topic
.在topic
上,我们创建了一个分支small_topic
,该分支从主题创建,最后被合并到其中.
We have mainly 2 branches - master
and topic
. HEAD points to topic
right now. On topic
we created a branch small_topic
which gets created from topic and in the end gets merged into it.
我们希望将主题重新定型为母版.我们运行git reabse -i master topic
.现在我们将看到此消息,我认为这是错误的!
We want to rebase topic onto master. We run git reabse -i master topic
. Now we will see this message which I think is wrong !
pick 490f6d3 t1
pick 6486a67 t2
pick b667871 t3
pick 37ae0d9 t4
pick 7dab544 s1
pick c94bb3b s2
pick b57cbbc t5
pick ea3543d t6
# Rebase 84d8343..ea3543d onto ea3543d (8 commands)
[请注意,您的SHA1与我的SHA1不同]
[Please note that your SHA1 will differ from mine]
可能的错误:将84d8343..ea3543d重置为ea3543d
为什么我们要继续使用onto ea3543d
?应该不是onto 84d8343
吗?但是,执行此操作后,仅会基于84d8343
.
Why we are seeing on onto onto ea3543d
? Should not it be onto 84d8343
? However, upon executing this rebases onto 84d8343
only.
此外,有趣的是-如果没有small_topic
分支,则该消息很好.只有当从该分支创建并合并到该分支中以进行重新设置的分支时(如topic
中的small_topic
),只有我看到了这一点.
Also, interesting thing is - if there was no small_topic
branch, then the message is fine. Only when there a branch which is created from and merged into the branch to be rebased (like small_topic
in topic
), then only I am seeing this.
这是一个错误吗?
推荐答案
是的,如果您要迁移到master上,它应该显示onto master
或onto 84d8343
.
Yes, if you are rebasing onto master, it should say onto master
or onto 84d8343
.
您的命令是git rebase -i master topic
.
这意味着先 git checkout topic
,然后再启动git rebase -i master
.
This means first, git checkout topic
, then start a git rebase -i master
.
这反过来意味着您的目标(--onto
参数)从上游默认设置;并且您的上游(commit-limiter)参数为master
.因此,onto
应该是master
(名称)或其哈希ID.
This in turn means that your target (--onto
argument) is defaulted from your upstream; and your upstream (commit-limiter) argument is master
. So the onto
should be either master
(the name) or its hash ID.
这似乎是生成注释的代码中的错误.提交列表(无论用master..topic
还是84d8343..ea3543d
表示)都是正确的,但是on目标不是.该错误的发生特别奇怪,但这可能是将git rebase
从shell脚本(更容易正确编写)重写为C的结果.
This appears to be a bug in the code that generates the comments. The list of commits, whether expressed as master..topic
or 84d8343..ea3543d
, is correct, but the onto target is not. The occurrence of the bug is particularly weird, but probably a consequence of rewriting git rebase
from shell script (which is much easier to get right) into C.
这篇关于Git重新定位可能的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!