Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does reachable/unreachable mean in git?

Tags:

git

Little bit confused..

In the git community manual, it says

The git log command can show lists of commits. On its own, it shows all commits reachable from the parent commit; but you can also make more specific requests

$ git log v2.5.. # commits since (not reachable from) v2.5

I thought git log by itself only shows you the commits made to the current branch, and the commits are sequential - so how can you have one commit made since another, but unreachable from it?

I think I'm either misuderstanding what git log does or what unreachable means or both.. grateful for any help!

like image 470
bruce Avatar asked Nov 06 '10 04:11

bruce


People also ask

Which command recovers commits that are not referenced by a branch or tag?

The git prune command is an internal housekeeping utility that cleans up unreachable or "orphaned" Git objects. Unreachable objects are those that are inaccessible by any refs. Any commit that cannot be accessed through a branch or tag is considered unreachable. git prune is generally not executed directly.

Which flag is used to filter commits by pattern or regular expression?

To filter commits by their commit message, use the --grep flag.


2 Answers

in Git, every commit you make (except for the very first) will have a parent commit. It follows that any given commit (except the first) is a child of one (or possibly more than one) other commit. You can also have several branches of development in Git, that begin or deviate at a particular ancestral commit. Nothing in Git dictates that commits must occur in either a chronological or linear order, and thus the git log tool needs to be able to deal with several ways of querying history.

For instance, assume I develop my application and make commits in alphabetical order:

---A---B---E---G
    \       \
     C---D   F

In this example, I must have made a new branch on commit A and E.

If I were to run git log <D> (where <D> is the commit's SHA), then the log history would look like this:

D---C---A---

From that commit, only the parents and their ancestor commits can be 'seen'. Commits B, E, F and G are technically 'unreachable' from commit D, as they share no common connected parent commit.

like image 73
Chris Avatar answered Oct 13 '22 01:10

Chris


"Y is reachable from X" means object Y is reachable from the DAG. Depends on what Y is, this can means:

  • Y is a commit: Y is a parent/ancestor of X.
  • Y is a directory/folder/blob: Y is a part of (to say) a commit in the parent/ancestor tree of X.

For some doc (e.g. git-fsck), it just say "Y is reachable". This means Y is reachable from some tag/branch (i.e. Y cannot be garbage collected)

like image 43
J-16 SDiZ Avatar answered Oct 13 '22 01:10

J-16 SDiZ