gitversion-controlrebasedata-loss

Git: Does rebasing and removing obsolete branches lose commit data?


Referring to this specific example in the Git Pro book on the Git website I have a question about rebasing:

What happens to the three commits C3, C4 and C10 when the final history appears as in Fig. 43 and the branches named "client" and "server" have been deleted? Are these commits no longer retrievable from git's database?

I realize the changes introduced in these commits will have been replayed onto the master branch in the form of the C3',C4' and C10' commits.

I was curious to know whether the original commits were lost after the rebase, as they are no longer documented in the history.

Thanks.


Solution

  • Commits C3, C4, and C10 are not lost after rebasing. They still exist in your local git repository, but they have become "unreachable". That means that there is no longer any path from a named reference (HEAD, branches, tags, etc) that leads to those commits. Git will eventually remove unreachable commits as part of its garbage collection process, but the default settings for the that are to remove commits older than two weeks.

    Until those commits are actually cleaned up by git, you can continue to reference them by commit id. You can make them reachable again by creating a new branch, as in:

    git checkout -b newbranch C10