{"id":17568,"date":"2022-07-11T17:53:22","date_gmt":"2022-07-11T08:53:22","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=17568"},"modified":"2023-05-27T18:55:41","modified_gmt":"2023-05-27T09:55:41","slug":"%e3%80%90git%e3%80%91%e3%80%8cpre-commit%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=17568","title":{"rendered":"\u3010Git\u3011\u300cpre-commit\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>pre-commit\u3068\u306f\uff1f<\/h2>\n<p>Git\u30d5\u30c3\u30af\u306e\u4e00\u7a2e\u3067\u7279\u5b9a\u306eGit\u64cd\u4f5c\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h3>\u30bf\u30a4\u30df\u30f3\u30b0<\/h3>\n<p>\u30b3\u30df\u30c3\u30c8\u3092\u30c8\u30ea\u30ac\u30fc\u306b\u3067\u304d\u308b\u3002<\/p>\n<h3>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea<\/h3>\n<p>git\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u306f\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u306e\u3067\u3001sample\u3068\u3044\u3046\u62e1\u5f35\u5b50\u3092\u9664\u53bb\u3059\u308c\u3070\u30b3\u30df\u30c3\u30c8\u6642\u306e\u52d5\u4f5c\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">.git\/hooks\/pre-commit.sample<\/pre>\n<p>\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u3057\u3066\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n<p>git\u306e\u7ba1\u7406\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3042\u308b\u306e\u3067git\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u3053\u3068\u3067\u3059\u3002\u306a\u306e\u3067\u30c1\u30fc\u30e0\u30e1\u30f3\u30d0\u30fc\u5185\u3067\u5171\u6709\u3059\u308b\u3053\u3068\u304c\u96e3\u3057\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u5bfe\u7b56<\/h4>\n<p>\u8a2d\u5b9a\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4e2d\u3067\u81ea\u52d5\u7684\u306b.git\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30b3\u30d4\u30fc\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<h3>\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9<\/h3>\n<p>pre-commit\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7528\u9014\u3067\u4f7f\u308f\u308c\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n<ul>\n<li>master\u3084develop\u30d6\u30e9\u30f3\u30c1\u3078\u306e\u30b3\u30df\u30c3\u30c8\u3092\u7981\u6b62\u3059\u308b\u3002<\/li>\n<li>\u30b3\u30f3\u30d5\u30ea\u30af\u30c8\u672a\u89e3\u6d88\u306e\u30bd\u30fc\u30b9\u304c\u3042\u3063\u305f\u3089\u30b3\u30df\u30c3\u30c8\u3055\u305b\u306a\u3044\u3002<\/li>\n<li>linter\u3092\u5b9f\u884c\u3057\u3066\u30a8\u30e9\u30fc\u304c\u3042\u3063\u305f\u3089\u30b3\u30df\u30c3\u30c8\u3055\u305b\u306a\u3044\u3002<\/li>\n<\/ul>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<p>\u304b\u306a\u308a\u306e\u56de\u6570\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u91cd\u3044\u51e6\u7406\u306f\u907f\u3051\u308b\u3053\u3068\u3002\uff08\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3092\u7d4c\u7531\u3055\u305b\u308b\u3088\u3046\u306a\u51e6\u7406\u306a\u3069\uff09<\/p>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"lang:default decode:true \">brew install pre-commit<\/pre>\n<h3>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u751f\u6210<\/h3>\n<pre class=\"lang:default decode:true\">pre-commit sample-config &gt; .pre-commit-config.yaml\r\n\/\/ \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u8aad\u307f\u8fbc\u307e\u305b\u308b\u3002\r\npre-commit install<\/pre>\n<h3>\u8a66\u3059\u3002<\/h3>\n<p>\u3053\u308c\u3067pre-commit\u304c\u52d5\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">git add -A\r\ngit commit -m \"\u3042\u3042\u3042\"<\/pre>\n<h4>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u9805\u76ee\u304c\u52d5\u304d\u307e\u3059\u3002<\/h4>\n<table>\n<tbody>\n<tr>\n<td>\u9805\u76ee<\/td>\n<td>\u8aac\u660e<\/td>\n<\/tr>\n<tr>\n<td>trailing-whitespace<\/td>\n<td>\u884c\u672b\u306e\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u3092\u524a\u9664\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>end-of-file-fixer<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u304c\u304b\u3089\u3067\u3042\u308b\u304b1\u3064\u306e\u6539\u884c\u3067\u3042\u308b\u304b\u30c1\u30a7\u30c3\u30af<\/td>\n<\/tr>\n<tr>\n<td>check-yaml<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u304c\u89e3\u6790\u53ef\u80fd\u306a\u69cb\u6587\u3067\u3042\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3002<\/td>\n<\/tr>\n<tr>\n<td>check-added-large-files<\/td>\n<td>\u5de8\u5927\u306a\u30d5\u30a1\u30a4\u30eb\u304c\u30b3\u30df\u30c3\u30c8\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Husky<\/h2>\n<p>JavaScript\u306a\u3089Husky\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3053\u3068\u3067\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306a\u3069\u3092\u66f8\u304b\u306a\u304f\u3066\u3082pre-commit\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"lang:default decode:true\">yarn add --dev husky\r\nyarn husky install<\/pre>\n<h3>\u8a2d\u5b9a<\/h3>\n<pre class=\"lang:default decode:true  \">{\r\n  \"scripts\": {\r\n    \"prepare\": \"husky install\"\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"pre-commit\u3068\u306f\uff1f Git\u30d5\u30c3\u30af\u306e\u4e00\u7a2e\u3067\u7279\u5b9a\u306eGit\u64cd\u4f5c\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u6a5f\u80fd\u3067\u3059\u3002 \u30bf\u30a4\u30df\u30f3\u30b0 \u30b3\u30df\u30c3\u30c8\u3092\u30c8\u30ea\u30ac\u30fc\u306b\u3067\u304d\u308b\u3002 \u30c7\u30a3\u30ec\u30af\u30c8\u30ea git\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u306f\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17568"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17568"}],"version-history":[{"count":13,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17568\/revisions"}],"predecessor-version":[{"id":20184,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/17568\/revisions\/20184"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17568"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}