下記のようにして、特定ディレクトリのみを対象にしたgit log
が可能です。
git log -- path/to/directory
はじめに
特定ディレクトリのみを対象にしてgit log
する方法がパッとわからなかったので、備忘録を残します。
特定ディレクトリを対象にgit logする
コマンド
--
の後にディレクトリを指定することで、特定ディレクトリを対象にgit logすることが可能です。
git log -- path/to/directory
--
は、オプション等とディレクトリ指定の区切りを示すものです。
--
以後に指定するものはファイルやディレクトリのパスですよ、という区切りの意味を持ちます。
Ref. Git - git-log Documentation
具体例
Kubernetesのレポジトリを題材に、実際にコマンドを実行してみます。
まずはそのままgit log
:
$ git log commit 0d9dccfc6bc22f2370650cf5b8ad99cbba74ea23 (HEAD -> master, origin/master, origin/HEAD) Merge: 66931f07d9c 95b926c93a4 Author: Kubernetes Prow Robot <20407524+k8s-ci-robot@users.noreply.github.com> Date: Sat Apr 19 16:20:59 2025 -0700 Merge pull request #131382 from liggitt/watch-list-e2e Correctly feature-gate WatchList e2e commit 95b926c93a456c3a1cb8177fdfae9617ac211cf8 Author: Jordan Liggitt <liggitt@google.com> Date: Sat Apr 19 17:18:31 2025 -0400 Feature-gate watchlist e2e commit 66931f07d9c3a4b8b7aecb5649d710896001047c Merge: b53b9fb5573 660df229bf3 Author: Kubernetes Prow Robot <20407524+k8s-ci-robot@users.noreply.github.com> Date: Fri Apr 18 07:55:08 2025 -0700 Merge pull request #131359 from deads2k/disable Stop exposing list-via-watch from the server commit 660df229bf3929741cf31659187060d0c651dcf9 Author: David Eads <deads@redhat.com> Date: Thu Apr 17 16:34:46 2025 -0400 Stop exposing list-via-watch from the server With StreamingCollectionEncodingToJSON and StreamingCollectionEncodingToProtobuf, the WatchList must re-justify its necessity. To prevent an ecosystem from building around a feature that may not be promoted, we will stop serving list-via-watch until performance numbers can justify its inclusion. This also stops the kube-controller-manager from using the list-via-watch by default. The fallback is a regular list, so during the skew during an upgrade the "right" thing will happen and the new StreamingCollectionEncoding will be used. commit b53b9fb5573323484af9a19cf3f5bfe80760abba Merge: 44c230bf5c3 a8f6d77c8da Author: Kubernetes Prow Robot <20407524+k8s-ci-robot@users.noreply.github.com> Date: Wed Apr 16 11:05:08 2025 -0700 Merge pull request #131015 from aojea/final_servicecidr Add the missing Conformance Test for ServiceCIDR and IPAddress APIS commit a8f6d77c8da6c5df574048884a54198314cee0ae Author: Antonio Ojea <aojea@google.com> Date: Tue Apr 15 14:52:14 2025 +0000 ServiceCIDR and IPAddess Conformance Change-Id: I6ee188cc8c163c312f8a8da9f1277d83e1ea634c
最新コミットから順にコミット履歴が表示されています。
次にgit log -- ./docs
で、./docs
ディレクトリを対象にしたgit log
を出力してみます。
$ git log -- ./docs commit 04b178b49bd35529de40dd84a18ebfd034b22096 Author: Jordan Liggitt <liggitt@google.com> Date: Wed Oct 5 14:24:21 2022 -0400 Make root approval non-recursive commit 9682b7248fb69733c2a0ee53618856e87b067f16 Author: Davanum Srinivas <davanum@gmail.com> Date: Mon Jan 3 10:59:47 2022 -0500 OWNERS cleanup - Jan 2021 Week 1 Signed-off-by: Davanum Srinivas <davanum@gmail.com> commit 56e092e382038b01c61fff96efb5982a2cb137cb Author: Benjamin Elder <bentheelder@google.com> Date: Sun Feb 28 14:17:42 2021 -0800 hack/update-bazel.sh commit 5c88b7f25b0781d60fea6017d3a939c0e962316c Author: Davanum Srinivas <davanum@gmail.com> Date: Tue Aug 11 10:35:20 2020 -0400 Add sigs for root folders Signed-off-by: Davanum Srinivas <davanum@gmail.com> commit b43c04452f3b563473b5c2a765d4ac18cc0ff58f Author: Roy Lenferink <lenferinkroy@gmail.com> Date: Wed Jan 30 20:05:00 2019 +0100 Updated OWNERS files to include link to docs commit 54e8d7392067598618805beba61ef719abfce28b Author: Lubomir I. Ivanov <lubomirivanov@vmware.com> Date: Sat Oct 20 21:15:03 2018 +0300 docs: stop tracking placeholder documentation The placeholder documentation introduces a couple of problems: - it complicates the contributor-experience (forces the CI to run N times before the contributor finds out that they need to call an .sh script and include certain files from docs/) - it forces CLI related pull requests for tools like kubeadm and kubectl to require top level approval from docs/OWNERS as such PRs still need to touch the .generated_docs file Stop tracking the placeholder documentation by applying the following actions: - remove the utility set-placeholder-gen-docs() - make verify-generated-docs.sh only generate in a temporary folder and not match .generated_docs - mark generate-docs.sh as an alias for update-generated-docs.sh - remove all current placeholder files in docs folders admin, man, user-guide, yaml - ignore the above folders and .generated_docs in a .gitignore file
このように、指定したディレクトに影響のあるコミットのみが抽出されて表示されました。
おわりに
以上、特定ディレクトリを対象にgit logする方法の簡単な備忘録でした。
どなたかの参考になれば幸いです。
[関連記事]