version control - Where does a Git branch start and what is its length? -
every , i'm asked, on commit branch on git starts or if commit has been created on specific branch. end point of branch pretty clear: that's branch label sits. - did start? trivial answer be: on commit created branch. information is, far know now, , that's why i'm asking question, lost after first commits.
as long know commit branched off, can draw graph make clear:
a - b - c - - - - j [master] \ d - e - f - g [branch-a] \ h - - [branch-b]
i've created branch-b @ commit e
that's "start". know that, because did it. can others recognize same way? draw same graph that:
a - b - c - - - - j [master] \ \ f - g [branch-a] \ / d - e \ h - [branch-b]
so, looking @ graph now, branch started @ e
, 1 @ b
? commit d
member of both branches or can decide whether belongs branch-a or branch-b?
this sounds philosophical isn't. supervisors know, when branch has been started (it marks start of task) , branch changes belong (to purpose of change - required work) , i'd know if git offers infos (tools, commands) or definitions answer questions correctly.
in git, every branch starts @ root commit, , quite literally true. guess that's not helpful you. instead define "the start of branch" in relation other branches. 1 way can use
git show-branch branch1 branch2 ... branchn
and show common commit between specified branches @ bottom of output (if there is, in fact, common commit).
here's example the linux kernel git documentation show-branch
$ git show-branch master fixes mhf * [master] add 'git show-branch'. ! [fixes] introduce "reset type" flag "git reset" ! [mhf] allow "+remote:local" refspec cause --force when fetching. --- + [mhf] allow "+remote:local" refspec cause --force when fetching. + [mhf~1] use git-octopus when pulling more 1 heads. + [fixes] introduce "reset type" flag "git reset" + [mhf~2] "git fetch --force". + [mhf~3] use .git/remote/origin, not .git/branches/origin. + [mhf~4] make "git pull" , "git fetch" default origin + [mhf~5] infamous 'octopus merge' + [mhf~6] retire git-parse-remote. + [mhf~7] multi-head fetch. + [mhf~8] start adding $git_dir/remotes/ support. *++ [master] add 'git show-branch'.
in example, master
being compared fixes
, mhf
branches. think of output table, each branch represented own column, , each commit getting own row. branches contain commit have +
or -
show in column in row commit.
at bottom of output, you'll see 3 branches share common ancestor commit, , in fact head
commit of master
:
*++ [master] add 'git show-branch'.
this means both fixes
, mhf
branched off of commit in master
.
alternative solutions
of course that's 1 possible way determine common base commit in git. other ways include git merge-base
find common ancestors, , git log --all --decorate --graph --oneline
or gitk --all
visualize branches , see diverge (though if there lot of commits becomes difficult quickly).
other questions original poster
as these questions had:
is commit
d
member of both branches or can decide whether belongsbranch-a
orbranch-b
?
d
member of both branches, it's ancestor commit both of them.
supervisors know, when branch has been started (it marks start of task)...
in git, can rewrite history of entire commit tree(s) , branches, when branch "starts" not set in stone in tfs or svn. can rebase
branches onto point in time in git tree, putting before root commit! therefore, can use "start" task @ point in time in tree want.
this common use case git rebase
, sync branches latest changes upstream branch, push them "forward" in time along commit graph, if had "just started" working on branch, though you've been working on while. push branches in time along commit graph, if wanted (though might have resolve lot of conflicts, depending on branch contents...or maybe won't). insert or delete branch right in middle of development history (though doing change commit shas of lot of commits). rewriting history 1 of primary features of git makes powerful , flexible.
this why commits come both authored date (when commit authored), , committed date (when commit last committed commit tree). can think of them analogous create time-date , last-modified time-date.
supervisors know...to branch changes belong to (to purpose of change - required work).
again, because git allows rewrite history, can (re)base set of changes on pretty branch/commit in commit graph want. git rebase
literally allows move entire branch around freely (though might need resolve conflicts go, depending on move branch , contains).
that being said, 1 of tools can use in git determine branches or tags contains set of changes --contains
:
# branches contains commit x? git branch --all --contains x # tags contains commit x? git tag --contains x
Comments
Post a Comment