Skip to content

Commit 8aa7b31

Browse files
committed
Add Find The Initial Commit as a git til
1 parent 87c57c7 commit 8aa7b31

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ _317 TILs and counting..._
7575
- [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md)
7676
- [Dry Runs in Git](git/dry-runs-in-git.md)
7777
- [Excluding Files Locally](git/excluding-files-locally.md)
78+
- [Find The Initial Commit](git/find-the-initial-commit.md)
7879
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
7980
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
8081
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)

git/find-the-initial-commit.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Find The Initial Commit
2+
3+
By definition, the initial commit in a repository has no parents. You can
4+
exploit that fact and use `rev-list` to find the initial commit; a commit
5+
with no parents.
6+
7+
```bash
8+
$ git rev-list --max-parents=0 HEAD
9+
```
10+
11+
The `rev-list` command lists all commits in reverse chronological order. By
12+
restricting them to those with at most 0 parents, you are only going to get
13+
root commits. Generally, a repository will only have a single root commit,
14+
but it is possible for there to be more than one.
15+
16+
See `man git-rev-list` for more details.

0 commit comments

Comments
 (0)