Hacker News new | ask | show | jobs
by JasperBall 3865 days ago
?

Just do something like:

    git rev-list --max-parents=0 HEAD
1 comments

This command doesn't make any sense to me. That's why I hate using git...
Let me attempt an explanation.

'git rev-list' will give you the SHA-1 hashes of all the commits reachable from a given commit. So 'git rev-list HEAD' is going to give you all commits reachable from HEAD, i.e. your latest one all the way to your first commit. After that, there's a bunch of ways you could filter that. For example, you could run 'git rev-list HEAD | tail -1' to get the hash of the first commit, and now all you need to do to show the whole diff is pipe it to 'xargs git show' (xargs reads from stdin and uses that as the argument to whatever comes after it.

The grandparent comment uses a slightly interesting trick – he/she used the built-in '--max-parents' filter. '--max-parents' limits the number of parent commits. For example, a merge has 2 or more parent commits, so the '--max-parents=1' option will exclude all merge commits. What commit has no parents? Why, the first commit of the repo, of course.

Hence, the command 'git rev-list --max-parents=0 HEAD | xargs git show'.

It's a query of the git commit history. List all commits which are direct or indirect ancestors of the `HEAD` (currently checked-out) commit, and which themselves don't have any ancestors (parents).

Personally, I would have used `master` instead of `HEAD` because any commit in git can be checked out, but `master` is highly likely to be the main line of development and thus be descended from the true first commit of the repository.