Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active December 1, 2023 05:09
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chapmanjacobd/cb8695e6b106c8c5d7285149266fab11 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/cb8695e6b106c8c5d7285149266fab11 to your computer and use it in GitHub Desktop.
a few interesting git commands

gitls

git ls-files --sparse --full-name -z | 
  xargs -0 -I FILE -P 20 git log --date=iso-strict-local --format='%ad %>(14) %cr %<(5) %an  %h ./FILE' -- FILE | 
  sort --general-numeric-sort

This lists the files and hashes for each git commit and file:

2021-12-05T13:32:32-06:00  1 year, 11 months ago  Jacob Chapman  cc91fa0 ./.gitattributes
2021-12-05T13:32:32-06:00  1 year, 11 months ago  Jacob Chapman  cc91fa0 ./.gitignore
2022-01-04T14:06:22-06:00  1 year, 10 months ago  Jacob Chapman  3924494 ./.gitignore
2022-01-08T15:41:51-06:00  1 year, 9 months ago  Jacob Chapman  e480ebc ./.gitignore
2022-04-18T11:00:26-05:00  1 year, 6 months ago  Jacob Chapman  fda297a ./.gitignore
...
2023-10-21T17:08:15-05:00     8 hours ago  Jacob Chapman  53676a4 ./xklb/utils/mpv_utils.py
2023-10-21T22:05:52-05:00     3 hours ago  Jacob Chapman  c7b9d06 ./xklb/media/media_player.py
2023-10-21T22:05:52-05:00     3 hours ago  Jacob Chapman  c7b9d06 ./xklb/scripts/mining/extract_links.py

gitls1

git ls-files --sparse --full-name -z | 
  xargs -0 -I FILE -P 20 git log -1 --date=iso-strict-local --format='%ad %>(14) %cr %<(5) %an  %h ./FILE' -- FILE | 
  sort --general-numeric-sort

Similar to the above but only showing the most recent hash for each file:

2022-07-29T18:24:19-05:00  1 year, 3 months ago  Jacob Chapman  b242dc1 ./tests/__init__.py
2022-08-13T23:48:19-05:00  1 year, 2 months ago  Jacob Chapman  018ca2e ./tests/data/test.opus
2022-08-15T00:05:04-05:00  1 year, 2 months ago  Jacob Chapman  eb3b340 ./.github/ISSUE_TEMPLATE/bug_report.md
2022-08-15T00:05:04-05:00  1 year, 2 months ago  Jacob Chapman  eb3b340 ./.github/ISSUE_TEMPLATE/feature_request.md
2022-08-15T00:16:05-05:00  1 year, 2 months ago  Jacob Chapman  b135a55 ./.github/FUNDING.yml
2022-08-27T22:09:38-05:00  1 year, 2 months ago  Jacob Chapman  83fd252 ./tests/data/test.eng.vtt
2022-08-27T22:09:38-05:00  1 year, 2 months ago  Jacob Chapman  83fd252 ./tests/data/test.mp4
2022-08-27T22:09:38-05:00  1 year, 2 months ago  Jacob Chapman  83fd252 ./tests/data/test.vtt
...

gitls-commits

git log --pretty=format: --name-only | sed '/^$/d' | sort | uniq -c | sort -g

This shows which files have been in commits the most:

...
193 xklb/player.py
211 xklb/utils.py
485 pyproject.toml
626 README.md
661 xklb/__init__.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment