mirror of
https://github.com/jbranchaud/til
synced 2026-03-04 23:18:44 +00:00
Compare commits
4 Commits
efddf19e91
...
76130792ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76130792ab | ||
|
|
872a1d2a00 | ||
|
|
5615da920f | ||
|
|
c60c63f554 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1565 TILs and counting..._
|
_1566 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||||
@@ -195,7 +195,7 @@ See some of the other learning resources I work on:
|
|||||||
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
||||||
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
||||||
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
||||||
- [Check For Cached Site Assocation File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
- [Check For Cached Site Association File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||||
@@ -304,6 +304,7 @@ See some of the other learning resources I work on:
|
|||||||
- [Configuring The Pager](git/configuring-the-pager.md)
|
- [Configuring The Pager](git/configuring-the-pager.md)
|
||||||
- [Copy A File From Another Branch](git/copy-a-file-from-another-branch.md)
|
- [Copy A File From Another Branch](git/copy-a-file-from-another-branch.md)
|
||||||
- [Count All Files Of Specific Type Tracked By Git](git/count-all-files-of-specific-type-tracked-by-git.md)
|
- [Count All Files Of Specific Type Tracked By Git](git/count-all-files-of-specific-type-tracked-by-git.md)
|
||||||
|
- [Count Number Of Commits On A Branch](git/count-number-of-commits-on-a-branch.md)
|
||||||
- [Create A New Branch With Git Switch](git/create-a-new-branch-with-git-switch.md)
|
- [Create A New Branch With Git Switch](git/create-a-new-branch-with-git-switch.md)
|
||||||
- [Delete All Untracked Files](git/delete-all-untracked-files.md)
|
- [Delete All Untracked Files](git/delete-all-untracked-files.md)
|
||||||
- [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md)
|
- [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md)
|
||||||
@@ -763,7 +764,7 @@ See some of the other learning resources I work on:
|
|||||||
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
- [Check Table For Any Orphaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||||
- [Checking Inequality](postgres/checking-inequality.md)
|
- [Checking Inequality](postgres/checking-inequality.md)
|
||||||
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
||||||
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
||||||
|
|||||||
48
git/count-number-of-commits-on-a-branch.md
Normal file
48
git/count-number-of-commits-on-a-branch.md
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Count Number Of Commits On A Branch
|
||||||
|
|
||||||
|
The `git rev-list` command will show all commits that fit the given revision
|
||||||
|
criteria. By adding in the `--count` flag, we get a count of the number of
|
||||||
|
commits that would have been displayed. Knowing this, we can get the count of
|
||||||
|
commits for the current branch like so:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git rev-list --count HEAD
|
||||||
|
4
|
||||||
|
```
|
||||||
|
|
||||||
|
This finds and counts commits from `HEAD` (usually the top of the current
|
||||||
|
branch) all the back in reverse chronological order to the beginning of the
|
||||||
|
branch (typically the beginning of the repository). This works exactly as
|
||||||
|
expected for a the `main` branch.
|
||||||
|
|
||||||
|
What about when we are on a feature branch though?
|
||||||
|
|
||||||
|
Let's say we've branched off `main` and made a few commits. And now we want the
|
||||||
|
count.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git rev-list --count HEAD
|
||||||
|
7
|
||||||
|
```
|
||||||
|
|
||||||
|
Unfortunately, that is counting up the commits on the feature branch but it
|
||||||
|
keeps counting all the way back to the beginning of the repo.
|
||||||
|
|
||||||
|
If we want a count of just the commits on the current branch, then we can
|
||||||
|
specify a range: from whatever `main` was when we branched to the `HEAD` of
|
||||||
|
this branch.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git rev-list --count HEAD
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the same as saying, I want all commits on `HEAD`, but exclude (`^`) the
|
||||||
|
commits on `main`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git rev-list --count HEAD ^main
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
See `man git-rev-list` for more details.
|
||||||
Reference in New Issue
Block a user