hogashi.*

日記から何から

Gitのサブコマンド眺めたりgit help help見たりした

 git help help を初めて見た。 #102: Do Developers Really Know How to Use Git Commands? A Large-scale Study Using Stack Overflow – Misreading Chat で Git のサブコマンドの話をしていて、 140個ある!って言っててマジか、と思って git help --all とかに辿り着いたりした。サブコマンドがジャンルごとに紹介されている。

$ git help --all --no-external-commands --no-alias | grep '^[^ ]'
See 'git help <command>' to read about a specific subcommand
Main Porcelain Commands
Ancillary Commands / Manipulators
Ancillary Commands / Interrogators
Interacting with Others
Low-level Commands / Manipulators
Low-level Commands / Interrogators
Low-level Commands / Syncing Repositories
Low-level Commands / Internal Helpers
User-facing repository, command and file interfaces
Developer-facing file formats, protocols and other interfaces

 あとそういえばと思って git help help 見たらもちろんあった。
git-scm.com
 よく見ると --man の他に --info とか --web とかがあることがわかっておもしろい。 Google Chrome など好きなブラウザのコマンドか実行ファイルへのパス*1を .gitconfig の web.browser に設定しておくとブラウザで HTML 形式のヘルプが見れる。例えば git help --web status を見るとfile:///opt/homebrew/Cellar/git/2.38.1/share/doc/git-doc/git-status.html が開かれていてそこにあるのか〜という感じ (ディレクトリを見るとたしかにたくさん入っている)。多分 git-scm.com で見れるものと内容は同じだと思う。

 全然関係ないけど、 git help --all --no-external-commands --no-alias (v2.38.1 時点) で見れるコマンドを全部 RegExp::Assemble *2 にかけるとこういう正規表現が得られる。見どころは c(at-file|he(ck(...|out(...|l(ean|i|one)|... あたりで、 check 系がいっぱいと、 cherry 系があるのと、 clean/cli/clone の cl 三兄弟がいるのと、その他 c 始まりがたくさんある。

$ rassemble $(git help --all --no-external-commands --no-alias | grep '^ ' | awk '{ print $1 }' | sort | tr '\n' ' ')
a(?:dd|m|nnotate|pply|rchi(?:mport|ve)|ttributes)|b(?:isect|lame|ranch|u(?:greport|ndle))|c(?:at-file|he(?:ck(?:-(?:attr|ignore|mailmap|ref-format)|out(?:-index)?)|rry(?:-pick)?)|itool|l(?:ean|i|one)|o(?:lumn|mmit(?:-(?:graph|tree))?|nfig|unt-objects)|redential(?:-(?:cach|stor)e)?|vs(?:(?:exportcommi|impor)t|server))|d(?:aemon|escribe|i(?:agnose|ff(?:-(?:files|index|tree)|tool)?))|f(?:ast-(?:ex|im)port|etch(?:-pack)?|ilter-branch|mt-merge-msg|or(?:-each-re(?:f|po)|mat-(?:(?:bundl|signatur)e|c(?:hunk|ommit-graph)|index|pa(?:ck|tch)))|sck)|g(?:c|et-tar-commit-id|it(?:k|web)|rep|ui)|h(?:ash-object|elp|ooks?|ttp-backend)|i(?:gnore|map-send|n(?:dex-pack|it|staweb|terpret-trailers))|l(?:og|s-(?:files|(?:remot|tre)e))|m(?:ai(?:l(?:info|map|split)|ntenance)|erge(?:-(?:(?:bas|(?:one-)?fil|tre)e|index)|tool)?|kt(?:ag|ree)|odules|ulti-pack-index|v)|n(?:ame-rev|otes)|p(?:4|a(?:ck-(?:objects|re(?:dundant|fs))|tch-id)|r(?:otocol-(?:c(?:apabilities|ommon)|http|pack|v2)|une(?:-packed)?)|u(?:ll|sh))|quiltimport|r(?:ange-diff|e(?:(?:ad-tre|bas|mot|rer)e|flog|p(?:ack|lace|ository-layout)|quest-pull|s(?:et|tore)|v(?:-(?:list|parse)|ert|isions))|m)|s(?:calar|end-(?:email|pack)|h(?:-(?:i18n|setup)|o(?:rtlog|w(?:-(?:branch|index|ref))?))|parse-checkout|t(?:a(?:sh|tus)|ripspace)|ubmodule|vn|witch|ymbolic-ref)|tag|u(?:npack-(?:file|objects)|pdate-(?:index|ref|server-info))|v(?:ar|er(?:ify-(?:commit|pack|tag)|sion))|w(?:hatchanged|(?:ork|rite-)tree)

 実際頭文字で数えると c 始まりが一番多いようでおもしろい。

$ git help --all --no-external-commands --no-alias | grep '^ ' | awk '{ print $1 }' | cut -c1 | sort | uniq -c | sort -nr
  25 c
  18 s
  17 r
  16 m
  16 f
  14 p
   8 d
   7 a
   6 i
   6 g
   5 v
   5 u
   5 h
   5 b
   4 l
   3 w
   2 n
   1 t
   1 q

 ちなみに正規表現Regexper で図にするとこうなった。長い。頭文字 c だけ抜粋したものを貼りつつ全部の図も details の中に入れておきます。

クリックして図の全体を見る (SVGです) Created with Snapaddmnnotatepplyrchimportvettributesbisectlameranchugreportndlecat-fileheck-attrignoremailmapref-formatout-indexrry-pickitoolleanioneolumnmmit-graphtreenfigunt-objectsredential-cachstorevsexportcommiimportserverdaemonescribeiagnoseff-filesindextreetoolfast-eximportetch-packilter-branchmt-merge-msgor-each-refpomat-bundlsignaturechunkommit-graphindexpacktchsckgcet-tar-commit-iditkwebrepuihash-objectelpooksttp-backendignoremap-sendndex-packitstawebterpret-trailerslogs-filesremottreemailinfomapsplitntenanceerge-basone-filtreeindextoolktagreeodulesulti-pack-indexvname-revotesp4ack-objectsredundantfstch-idrotocol-capabilitiesommonhttppackv2une-packedullshquiltimportrange-diffead-trebasmotrereflogpacklaceository-layoutquest-pullsettorev-listparseertisionsmscalarend-emailpackh-i18nsetuportlogw-branchindexrefparse-checkouttashtusripspaceubmodulevnwitchymbolic-reftagunpack-fileobjectspdate-indexrefserver-infovarerify-commitpacktagsionwhatchangedorkrite-tree

*1:Google Chrome の場所は特に Mac だとよくわからないけど Chrome Browser debug logs - Chrome Enterprise and Education Help とかを見るとわかる

*2:実際使ったのは itchyny/rassemble-go