Upgrade to Pro — share decks privately, control downloads, hide ads and more …

So You Think You Know Git - Part 2

Scott Chacon
February 29, 2024

So You Think You Know Git - Part 2

The second part of my So You Think You Know Git talk series. In this edition, we cover:

* switch and restore
* hooks
* attributes, smudge and clean filters
* fixup commits
* rebasing stacks
* scalar
* worktrees

Scott Chacon

February 29, 2024
Tweet

More Decks by Scott Chacon

Other Decks in Programming

Transcript

  1. - There are ~145 commands in Git - There are

    still an average of 9 commits per day - ~10k commits in the last 3 years - Do you know it all? How Well Do You Know Git?
  2. -switch and restore -hooks -attributes, smudge and clean filters -fixup

    commits -rebasing stacks -scalar -worktrees Let's Do This
  3. Let's Do This -switch and restore -hooks -attributes, smudge and

    clean filters -fixup commits -rebasing stacks -scalar -worktrees Shotgun buffet
  4. Let's Do This Shotgun buffet blog.gitbutler.com -switch and restore -hooks

    -attributes, smudge and clean filters -fixup commits -rebasing stacks -scalar -worktrees
  5. Switch and Restore ❯ git checkout branch ❯ git checkout

    file.txt ❯ git checkout HEAD@{10.minutes.ago} -- file.txt ❯ git checkout -p file.txt
  6. Switch and Restore ❯ git checkout branch ❯ git switch

    branch ❯ git switch -c new_branch
  7. Switch and Restore ❯ git checkout file.txt ❯ git restore

    file.txt ❯ git restore -- source HEAD@{10.minutes.ago} file.txt ❯ git restore -p file.txt
  8. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (28)
  9. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (24) (- git email stuff)
  10. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (20) (- perforce stuff)
  11. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (14) (- server stuff)
  12. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (11) (- MS scaling stuff)
  13. Hooks - applypatch-msg - pre-applypatch - post-applypatch - pre-commit -

    pre-merge-commit - prepare-commit-msg - commit-msg - post-commit - pre-rebase - post-checkout - post-merge - pre-push - pre-receive - update - proc-receive - post-receive - post-update - reference-transaction - push-to-checkout - pre-auto-gc - post-rewrite - sendemail-validate - fsmonitor-watchman - p4-changelist - p4-prepare-changelist - p4-post-changelist - p4-pre-submit - post-index-change (11)
  14. Hooks - pre-commit - prepare-commit-msg - commit-msg - post-commit -

    pre-rebase - post-rewrite - post-merge - pre-merge-commit - post-checkout - reference-transaction - pre-push (11) Commit Stuff Rewriting Stuff Merging Stuff Switching/Pushing Stuff
  15. Hooks: Examples - commit message formatting - package install -

    update ctags - submodule status - tabs or spaces - linting - large files - test passes - rebasing merged commit prevention
  16. Attributes ❯ git diff diff -- git a/image.png b/image.png index

    88839c4 .. 4afcb7c 100644 Binary files a/image.png and b/image.png differ
  17. Attributes ❯ exiftool image.png ExifTool Version Number : 7.74 File

    Name : image.png Directory : . File Size : 94 kB File Modification Date/Time : 2009 : 04 : 21 07 : 02 : 43-07 : 00 File Type : PNG MIME Type : image/png Image Width : 1056 Image Height : 827 Bit Depth : 8 Color Type : RGB with Alpha Compression : Deflate/Inflate Filter : Adaptive Interlace : Noninterlaced Profile CMM Type : appl
  18. Attributes ❯ echo '*.png diff=exif' >> .gitattributes # take every

    file that ends in png # and pre-process them with a strategy called ‘exif’ ❯ git config diff.exif.textconv exiftool # the 'exif' strategy is to run exiftool on the file
  19. Attributes ❯ echo '*.png diff=exif' >> .gitattributes # take every

    file that ends in png # and pre-process them with a strategy called ‘exif’ ❯ git config diff.exif.textconv exiftool # the 'exif' strategy is to run exiftool on the file
  20. Smudge and Clean: RCS Keywords / * $Id$ $Header$ $Date$

    $DateTime$ $Change$ $File$ $Revision$ $Author$ * /
  21. Smudge and Clean: RCS Keywords / * $Id: // depot/test/main.c#10

    $ $Header: // depot/test/main.c#10 $ $Date: 2006/06/21 $ $DateTime: 2006/06/21 17 : 42 : 19 $ $Change: 1745 $ $File: / / depot/test/main.c $ $Revision: #10 $ $Author: michael $ / *
  22. Smudge and Clean: LFS ❯ brew install git-lfs ❯ git

    lfs install Updated Git hooks. Git LFS initialized. ❯ git lfs track "*.mov" Tracking "*.mov" ❯ git commit -am 'commit movie' [master c0258ddeba] commit movie 1 files changed, 83 insertions(+) create mode 100644 Timeline 1.mov
  23. Smudge and Clean: LFS ❯ brew install git-lfs ❯ git

    lfs install Updated Git hooks. Git LFS initialized. ❯ git lfs track "*.mov" Tracking "*.mov" ❯ git commit -am 'commit movie' [master c0258ddeba] commit movie 1 files changed, 83 insertions(+) create mode 100644 Timeline 1.mov
  24. Smudge and Clean: LFS ❯ brew install git-lfs ❯ git

    lfs install Updated Git hooks. Git LFS initialized. ❯ git lfs track "*.mov" Tracking "*.mov" ❯ git commit -am 'commit movie' [master c0258ddeba] commit movie 1 files changed, 83 insertions(+) create mode 100644 Timeline 1.mov
  25. Smudge and Clean: LFS ❯ brew install git-lfs ❯ git

    lfs install Updated Git hooks. Git LFS initialized. ❯ git lfs track "*.mov" Tracking "*.mov" ❯ git commit -am 'commit movie' [master c0258ddeba] commit movie 1 files changed, 83 insertions(+) create mode 100644 Timeline 1.mov
  26. Smudge and Clean: LFS ❯ git cat-file -p HEAD:"Timeline 1.mov"

    version https: // git-lfs.github.com/spec/v1 oid sha256 : 683d9e177ed4694aa8e99a0de86a79fb929805f5799d036cd4dfe11aa0dc1a97 size 508537858 ❯ cat .gitattributes *.mov filter=lfs diff=lfs merge=lfs -text
  27. Smudge and Clean: LFS ❯ git cat-file -p HEAD:"Timeline 1.mov"

    version https: // git-lfs.github.com/spec/v1 oid sha256 : 683d9e177ed4694aa8e99a0de86a79fb929805f5799d036cd4dfe11aa0dc1a97 size 508537858 ❯ cat .gitattributes *.mov filter=lfs diff=lfs merge=lfs -text
  28. Scaling Git ❯ scalar usage: scalar [-C <directory > ]

    [-c <key>=<value > ] <command> [< options >] Commands: clone list register unregister run reconfigure delete help version diagnose
  29. Scaling Git ❯ scalar usage: scalar [-C <directory > ]

    [-c <key>=<value > ] <command> [< options >] Commands: clone list register unregister run reconfigure delete help version diagnose
  30. Worktrees - working on more than one branch at a

    time - provide a new working directory for each branch
  31. Thank you! Be sure to let us buy you a

    beer at our drinkup tonight! B'Femme, 7p
  32. Be sure to let us buy you a beer at

    our drinkup tonight! B'Femme, 6p