Reputation: 4940
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.
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
The history will look like this -
* 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
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.
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)
[Please note that your SHA1 will differ from mine]
Possible Bug : Rebase 84d8343..ea3543d onto ea3543d
Why we are seeing on onto onto ea3543d
? Should not it be onto 84d8343
? However, upon executing this rebases onto 84d8343
only.
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.
Is this a bug ?
Upvotes: 3
Views: 540
Reputation: 487755
Yes, if you are rebasing onto master, it should say onto master
or onto 84d8343
.
Your command was git rebase -i master topic
.
This means first, git checkout topic
, then start a git rebase -i master
.
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.
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.
Upvotes: 5