goelakash goelakash - 3 months ago 11
Git Question

Number of commits reduced after rebasing feature branch over master

So I have forked a branch from

master
, lets say
feature
. Both branches got differing commits added to them afterwards. As of now,
feature
currently has 1537 commits, and
master
has 1515 commits.

In order to get some updates, I rebased the
feature
over
master
, so after doing
git rebase -i master
on
feature
, the number of commits are reduced to 1532 (
feature
branch).

I can't think of a situation where this is possible. Say at the time of fork, both had
x
commits, and later,
y
commits were added to
master
, whereas
z
commits were added to
feature
. So
master
has
x+y
commits and
feature
has
x+z
commits.
If
feature
has been rebased over master, then it should have
x+y+z
commits, and at least not less than
x+z
. What am I missing?

Answer

Rebase works something like this:

foreach (commit) {
    calculate diff
    apply diff
    git add
    git commit
}

If there's any duplication between your work on feature and master, then it's likely that many of these reduce to empty commits. Thus Git elided them.

If you invoke rebase with the --keep-empty flag, these empty commits should be preserved.