gitversion-controlbranchrevision-history

Does deleting a branch in git remove it from the history?


Coming from svn, just starting to become familiar with git.

When a branch is deleted in git, is it removed from the history?

In svn, you can easily recover a branch by reverting the delete operation (reverse merge). Like all deletes in svn, the branch is never really deleted, it's just removed from the current tree.

If the branch is actually deleted from the history in git, what happens to the changes that were merged from that branch? Are they retained?


Solution

  • Branches are just pointers to commits in git. In git each commit has a complete source tree, it is a very different structure from svn where all branches and tags (by convention) live in separate 'folders' of the repository alongside the special 'trunk'.

    If the branch was merged into another branch before it was deleted then all of the commits will still be reachable from the other branch when the first branch is deleted. They remain exactly as they were.

    If the branch is deleted without being merged into another branch then the commits in that branch (up until the point where the forked from a commit that is still reachable) will cease to be visible.

    The commits will still be retained in the repository and it is possible to recover them immediately after the delete, but eventually they will be garbage collected.