From 8aa7b31a8f0178c06db4eb267d766086c8a21536 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 1 Feb 2016 21:30:22 -0600 Subject: [PATCH] Add Find The Initial Commit as a git til --- README.md | 1 + git/find-the-initial-commit.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 git/find-the-initial-commit.md diff --git a/README.md b/README.md index 242fb73..e864f14 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ _317 TILs and counting..._ - [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md) - [Dry Runs in Git](git/dry-runs-in-git.md) - [Excluding Files Locally](git/excluding-files-locally.md) +- [Find The Initial Commit](git/find-the-initial-commit.md) - [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md) - [Grep Over Commit Messages](git/grep-over-commit-messages.md) - [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md) diff --git a/git/find-the-initial-commit.md b/git/find-the-initial-commit.md new file mode 100644 index 0000000..96fc079 --- /dev/null +++ b/git/find-the-initial-commit.md @@ -0,0 +1,16 @@ +# Find The Initial Commit + +By definition, the initial commit in a repository has no parents. You can +exploit that fact and use `rev-list` to find the initial commit; a commit +with no parents. + +```bash +$ git rev-list --max-parents=0 HEAD +``` + +The `rev-list` command lists all commits in reverse chronological order. By +restricting them to those with at most 0 parents, you are only going to get +root commits. Generally, a repository will only have a single root commit, +but it is possible for there to be more than one. + +See `man git-rev-list` for more details.