merge - Why does git branch history remain when the branch has been deleted -
i have deleted branch in git, , have confirmed no longer exists running:
git branch -a however, still able view branch, although unlabelled, using git gui tool.

is standard behaviour? expecting history of branch part of branch merged into.
the history of branch is part of branch merged into. if run git log branch merged you'll see commit(s) in branch merged from. part of history.
so why still "seeing branch"? because see there series of ancestor-descendant relationships, not branches.
a "branch" in git not series of commits. treat way, because makes sense our mental models, branch movable tag. it's name assigned specific commit. when you're working on branch x, , create new commit, git creates commit, sets parent current commit x points to, moves branch x point new commit.
so, suppose you're in branch master. branch master pointint commit 1 (i'll use numbers refer commits; git uses hashes, makes no difference). make changes, run git commit. means git creates new commit, commit 2. commit 2's parent commit 1. moves tag master commit 2. if open git gui tool, you'll see master @ commit 2, line commit 1 below it. that's because 1 2's parent commit.
so suppose create new branch. run git branch new; git checkout new. you're standing in branch new. branch new created standing, it's pointint commit 2. in gui tool you'll see master , new both pointing commit 2.
now make changes, run git commit. creates commit 3, has commit 2 parent, , move branch tag new 3. branch tag master still pointing 2.
now go master, git checkout master, make changes, git commit. again, new commit (let's 4), 1 has 2 parent. in gui tool can see both 3 , 4 have line connecting them 2.
now, part that's relevant question. still in master, run git merge new. merge in branch new. merge in git? merge commit instead of having 1 parent commit, has 2 parent commits. when run git merge new git create new commit 5, , set both commits 3 , 4 parents (4 because it's 1 master points to, 3 because it's 1 new points to). if open gui tool, see expect see in case: master pointing 5, , two lines it, 1 4, , 1 3, because both commits 5's parents. since haven't told git otherwise, still see new branch marking commit 3.
now, git history created independent of branches, , still exist if delete branches. remember, branch tag attached commit. deleting branch doesn't delete commit, or of history, removes tag. can run git branch -d new, , branch new disappear. however, commit 3, "in branch new", still there. commit 3's parent still 2, , commit 3 still 1 of 5's parents. happens if @ gui tool? well, you'll see commit 5 marked master, 2 lines coming out of it, marking commits 4 , 3 parents, lines 4 , 3 marking 2 parent, line 2 1. same before removing new branch.
i hope makes clear.
Comments
Post a Comment