0

I've been following Scott Chacon's Pro Git Book and I'm reaching the end of chapter 3 in which we have just done a three way merge. See the diagram below (my own drawn diagram not a screen grab of the book):

enter image description here

After doing the merge of 'master' with 'issue53', resulting in merge commit c6, the author says we can delete branch 'issue53'.

git branch -d issue53

What actually happens to that branch under the hood and what would the resultant diagram look like? I ask this because the author does not address the issue. Would the branch still be there but just not pointed to? or is there some magic going on that I'm unaware of?

torek
  • 448,244
  • 59
  • 642
  • 775
Andrew S
  • 2,847
  • 3
  • 33
  • 50
  • 1
    This diagram looks unlike what I am used to seeing. In any case, when you delete a branch, the commits in that branch will persist if they are referred to by other branches, which would probably be the case here, at least for most of the commits. Actually, even if you nuke a branch, all commits would still be listed in the reflog, at least for a time. – Tim Biegeleisen Mar 21 '18 at 01:29
  • Tim, I simplified the diagram to cut to the core point. I'd be interested to know ow you'd draw it differently. – Andrew S Mar 21 '18 at 01:46
  • Hi Andrew, are you certain this is a three way merge? From what I can see, commit `C6` only has two, not three, parents. – Tim Biegeleisen Mar 21 '18 at 01:52
  • The text book calls it so, so I presume its correct. This is because the merge requires C2, C4 and C5. – Andrew S Mar 21 '18 at 03:32
  • @TimBiegeleisen (and Andrew S): the term *three way merge* refers to the single ancestor plus two versions that are its inputs. See https://en.wikipedia.org/wiki/Merge_(version_control)#Three-way_merge – torek Mar 21 '18 at 04:35
  • @torek Yes, I realized that. Thanks for clarifying. – Tim Biegeleisen Mar 21 '18 at 04:37
  • Imagine this situation, if you had a file index.js and you edited it in both, c4 and c5, then the only way it can build a version of index.js for c6 is by showing how those files changed from the common ancestor c2. – Andrew S Mar 21 '18 at 13:07

2 Answers2

2

What actually happens to that branch under the hood

That depends on what you mean by the word branch. See What exactly do we mean by "branch"?

and what would the resultant diagram look like?

Drawing it in ASCII rather than fancy graphics, I get:

C0<-C1<-C2<-C4<---C6   <-- master (HEAD)
          \      /
           C3<-C5

That is, nothing happens to the commits at all. The name issue53, however, which used to point to commit C5, no longer exists (at all).

Since every commit in the diagram is still find-able by starting from the name master and working backwards, every commit remains protected from Git's garbage collection process.

torek
  • 448,244
  • 59
  • 642
  • 775
1

A branch in git is just a pointer to a commit, and it has a very simple implementation - it is a text file containing the checksum of a commit it is pointing to.

So in this example, you would have a file .git/refs/heads/issue53 that represents your branch (is your branch).

And when you delete a branch in git, you delete that text file (pointer) representing that branch. In this case, .git/refs/heads/issu53

zspajich
  • 11
  • 2