CINXE.COM

Git - Git Hooks

<!DOCTYPE html> <html lang="uz"> <head> <meta charset='utf-8'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Git - Git Hooks</title> <link href="/favicon.ico" rel='shortcut icon' type='image/x-icon'> <link rel="stylesheet" href="/application.min.css"> <script src="/js/modernizr.js"></script> <script src="/js/modernize.js"></script> </head> <body id="documentation"> <div class="inner"> <header> <a href="/"><img src="/images/logo@2x.png" width="110" height="46" alt="Git" /></a> <span id="tagline"></span> <script type="text/javascript"> const taglines = [ "fast-version-control", "everything-is-local", "distributed-even-if-your-workflow-isnt", "local-branching-on-the-cheap", "distributed-is-the-new-centralized" ]; var tagline = taglines[Math.floor(Math.random() * taglines.length)]; document.getElementById('tagline').innerHTML = '--' + tagline; </script> <form id="search" action="/search/results"> <input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" /> </form> <div id="search-results"></div> </header> </div> <div class="inner"> <div id="content-wrapper"> <div tabindex="1" class="sidebar-btn"></div> <aside class="sidebar" id="sidebar"> <nav> <ul> <li> <a href="/about">About</a> <ul> </ul> </li> <li> <a href="/doc" class="active">Documentation</a> <ul class="expanded"> <li> <a href="/docs">Reference</a> </li> <li> <a href="/book" class="active">Book</a> </li> <li> <a href="/videos">Videos</a> </li> <li> <a href="/doc/ext">External Links</a> </li> </ul> </li> <li> <a href="/downloads">Downloads</a> <ul > <li> <a href="/downloads/guis">GUI Clients</a> </li> <li> <a href="/downloads/logos">Logos</a> </li> </ul> </li> <li> <a href="/community">Community</a> </li> </ul> <hr class="sidebar"> <p> This book is available in <a href="/book/en/v2/Customizing-Git-Git-Hooks">English</a>. </p> <p> Full translation available in <table> <tr><td><a href="/book/az/v2/Git%e2%80%99i-F%c9%99rdil%c9%99%c5%9fdirm%c9%99k-Git-Hook%e2%80%99lar%c4%b1">azərbaycan dili</a>,</td></tr> <tr><td><a href="/book/bg/v2/Git-%d0%bd%d0%b0-%d0%bd%d0%b8%d1%81%d0%ba%d0%be-%d0%bd%d0%b8%d0%b2%d0%be-Git-%d1%80%d0%b5%d1%84%d0%b5%d1%80%d0%b5%d0%bd%d1%86%d0%b8%d0%b8">български език</a>,</td></tr> <tr><td><a href="/book/de/v2/Git-einrichten-Git-Hooks">Deutsch</a>,</td></tr> <tr><td><a href="/book/es/v2/Personalizaci%c3%b3n-de-Git-Puntos-de-enganche-en-Git">Español</a>,</td></tr> <tr><td><a href="/book/fr/v2/Personnalisation-de-Git-Crochets-Git">Français</a>,</td></tr> <tr><td><a href="/book/gr">Ελληνικά</a>,</td></tr> <tr><td><a href="/book/ja/v2/Git-%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%9e%e3%82%a4%e3%82%ba-Git-%e3%83%95%e3%83%83%e3%82%af">日本語</a>,</td></tr> <tr><td><a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-Hooks">한국어</a>,</td></tr> <tr><td><a href="/book/nl/v2/Git-aanpassen-Git-Hooks">Nederlands</a>,</td></tr> <tr><td><a href="/book/ru/v2/%d0%9d%d0%b0%d1%81%d1%82%d1%80%d0%be%d0%b9%d0%ba%d0%b0-Git-%d0%a5%d1%83%d0%ba%d0%b8-%d0%b2-Git">Русский</a>,</td></tr> <tr><td><a href="/book/sl/v2/Prilagoditev-Gita-Kljuke-Git">Slovenščina</a>,</td></tr> <tr><td><a href="/book/tl/v2/Pag-aangkop-sa-Sariling-Pangangailagan-ng-Git-Mga-Hook-ng-Git">Tagalog</a>,</td></tr> <tr><td><a href="/book/uk/v2/%d0%9d%d0%b0%d0%bb%d0%b0%d1%88%d1%82%d1%83%d0%b2%d0%b0%d0%bd%d0%bd%d1%8f-Git-%d0%93%d0%b0%d0%ba%d0%b8-hooks-Git">Українська</a></td></tr> <tr><td><a href="/book/zh/v2/%e8%87%aa%e5%ae%9a%e4%b9%89-Git-Git-%e9%92%a9%e5%ad%90">简体中文</a>,</td></tr> </table> </p> <p> Partial translations available in <table> <tr><td><a href="/book/cs/v2/Customizing-Git-Git-Hooks">Čeština</a>,</td></tr> <tr><td><a href="/book/mk/v2/%d0%9f%d0%b5%d1%80%d1%81%d0%be%d0%bd%d0%b0%d0%bb%d0%b8%d0%b7%d0%b0%d1%86%d0%b8%d1%98%d0%b0-%d0%bd%d0%b0-Git-Git-Hooks">Македонски</a>,</td></tr> <tr><td><a href="/book/pl/v2/Dostosowywanie-Gita-Git-Hooks">Polski</a>,</td></tr> <tr><td><a href="/book/sr/v2/%d0%9f%d1%80%d0%b8%d0%bb%d0%b0%d0%b3%d0%be%d1%92%d0%b0%d0%b2%d0%b0%d1%9a%d0%b5-%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%b0-%d0%93%d0%b8%d1%82-%d0%93%d0%b8%d1%82-%d0%ba%d1%83%d0%ba%d0%b5">Српски</a>,</td></tr> <tr><td><a href="/book/uz/v2/Customizing-Git-Git-Hooks">Ўзбекча</a>,</td></tr> <tr><td><a href="/book/zh-tw/v2/Customizing-Git-Git-Hooks">繁體中文</a>,</td></tr> </table> </p> <p> Translations started for <table> <tr><td><a href="/book/be/v2/Customizing-Git-Git-Hooks">Беларуская</a>,</td></tr> <tr><td><a href="/book/fa/v2/Customizing-Git-Git-Hooks" dir="rtl">فارسی</a>,</td></tr> <tr><td><a href="/book/id/v2/Kostumisasi-Git-Git-Hooks">Indonesian</a>,</td></tr> <tr><td><a href="/book/it/v2/Customizing-Git-Git-Hooks">Italiano</a>,</td></tr> <tr><td><a href="/book/ms/v2/Customizing-Git-Git-Hooks">Bahasa Melayu</a>,</td></tr> <tr><td><a href="/book/pt-br/v2/Customizing-Git-Git-Hooks">Português (Brasil)</a>,</td></tr> <tr><td><a href="/book/pt-pt/v2/Personalizar-o-Git-Git-Hooks">Português (Portugal)</a>,</td></tr> <tr><td><a href="/book/sv/v2/Customizing-Git-Git-Hooks">Svenska</a>,</td></tr> <tr><td><a href="/book/tr/v2/Git%e2%80%99i-%c3%96zelle%c5%9ftirmek-Git-Kancalar%c4%b1-Hooks">Türkçe</a>.</td></tr> </table> </p> <hr class="sidebar"/> <p> The source of this book is <a href="https://github.com/progit/progit2-uz">hosted on GitHub.</a></br> Patches, suggestions and comments are welcome. </p> </nav> </aside> <div id="content"> <div id="book-chapters"> <a class="dropdown-trigger" id="book-chapters-trigger" data-panel-id="chapters-dropdown" href="#">Chapters ▾</a> <div class='dropdown-panel' id='chapters-dropdown'> <div class='three-column'> <div class="column-left"> <ol class='book-toc'> <li class='chapter'> <h2>1. <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-%d0%a2%d0%b0%d0%bb%d2%9b%d0%b8%d0%bd%d0%bb%d0%b0%d1%80%d0%bd%d0%b8-%d0%b1%d0%be%d1%88%d2%9b%d0%b0%d1%80%d0%b8%d1%88-%d2%b3%d0%b0%d2%9b%d0%b8%d0%b4%d0%b0">Иш бошланиши</a></h2> <ol> <li> 1.1 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-%d0%a2%d0%b0%d0%bb%d2%9b%d0%b8%d0%bd%d0%bb%d0%b0%d1%80%d0%bd%d0%b8-%d0%b1%d0%be%d1%88%d2%9b%d0%b0%d1%80%d0%b8%d1%88-%d2%b3%d0%b0%d2%9b%d0%b8%d0%b4%d0%b0">Талқинларни бошқариш ҳақида</a> </li> <li> 1.2 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-Git-%d0%bd%d0%b8%d0%bd%d0%b3-%d2%9b%d0%b8%d1%81%d2%9b%d0%b0%d1%87%d0%b0-%d1%82%d0%b0%d1%80%d0%b8%d1%85%d0%b8">Git нинг қисқача тарихи</a> </li> <li> 1.3 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-Git-%d0%b0%d1%81%d0%be%d1%81%d0%b8">Git асоси</a> </li> <li> 1.4 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-%d0%9a%d0%be%d0%bc%d0%b0%d0%bd%d0%b4%d0%b0%d0%bb%d0%b0%d1%80-%d1%81%d0%b0%d1%82%d1%80%d0%b8">Командалар сатри</a> </li> <li> 1.5 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-Git-%d0%bd%d0%b8-%d1%9e%d1%80%d0%bd%d0%b0%d1%82%d0%b8%d1%88">Git ни ўрнатиш</a> </li> <li> 1.6 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-Git-%d0%b4%d0%b0-%d0%b1%d0%b8%d1%80%d0%b8%d0%bd%d1%87%d0%b8-%d1%81%d0%be%d0%b7%d0%bb%d0%b0%d1%88%d0%bb%d0%b0%d1%80">Git да биринчи созлашлар</a> </li> <li> 1.7 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-%d2%9a%d0%b0%d0%bd%d0%b4%d0%b0%d0%b9-%d1%91%d1%80%d0%b4%d0%b0%d0%bc-%d0%be%d0%bb%d0%b8%d1%88-%d0%bc%d1%83%d0%bc%d0%ba%d0%b8%d0%bd%3F">Қандай ёрдам олиш мумкин?</a> </li> <li> 1.8 <a href="/book/uz/v2/%d0%98%d1%88-%d0%b1%d0%be%d1%88%d0%bb%d0%b0%d0%bd%d0%b8%d1%88%d0%b8-%d0%a5%d1%83%d0%bb%d0%be%d1%81%d0%b0%d0%bb%d0%b0%d1%80">Хулосалар</a> </li> </ol> </li> <li class='chapter'> <h2>2. <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-Git-%d0%be%d0%bc%d0%b1%d0%be%d1%80%d0%b8%d0%bd%d0%b8-%d1%8f%d1%80%d0%b0%d1%82%d0%b8%d1%88">Git асослари</a></h2> <ol> <li> 2.1 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-Git-%d0%be%d0%bc%d0%b1%d0%be%d1%80%d0%b8%d0%bd%d0%b8-%d1%8f%d1%80%d0%b0%d1%82%d0%b8%d1%88">Git омборини яратиш</a> </li> <li> 2.2 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%8e%d0%b7%d0%b3%d0%b0%d1%80%d0%b8%d1%88%d0%bb%d0%b0%d1%80%d0%bd%d0%b8-%d0%be%d0%bc%d0%b1%d0%be%d1%80%d0%b3%d0%b0-%d1%91%d0%b7%d0%b8%d1%88">Ўзгаришларни омборга ёзиш</a> </li> <li> 2.3 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%a4%d0%b8%d0%ba%d1%81%d0%b8%d1%80%d0%bb%d0%b0%d1%88%d0%bb%d0%b0%d1%80-%d1%82%d0%b0%d1%80%d0%b8%d1%85%d0%b8%d0%bd%d0%b8-%d0%ba%d1%9e%d1%80%d0%b8%d1%88">Фиксирлашлар тарихини кўриш</a> </li> <li> 2.4 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%8e%d0%b7%d0%b3%d0%b0%d1%80%d0%b8%d1%88%d0%bb%d0%b0%d1%80%d0%bd%d0%b8-%d0%b1%d0%b5%d0%ba%d0%be%d1%80-%d2%9b%d0%b8%d0%bb%d0%b8%d1%88">Ўзгаришларни бекор қилиш</a> </li> <li> 2.5 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%a3%d0%b7%d0%be%d2%9b-%d0%bc%d0%b0%d1%81%d0%be%d1%84%d0%b0%d0%b4%d0%b0%d0%b3%d0%b8-%d0%be%d0%bc%d0%b1%d0%be%d1%80%d0%bb%d0%b0%d1%80-%d0%b1%d0%b8%d0%bb%d0%b0%d0%bd-%d0%b8%d1%88%d0%bb%d0%b0%d1%88">Узоқ масофадаги омборлар билан ишлаш</a> </li> <li> 2.6 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%a2%d0%b0%d0%bc%d2%93%d0%b0%d0%bb%d0%b0%d1%88">Тамғалаш</a> </li> <li> 2.7 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-Git-%d0%b4%d0%b0-%d1%82%d0%b0%d2%b3%d0%b0%d0%bb%d0%bb%d1%83%d1%81%d0%bb%d0%b0%d1%80">Git да таҳаллуслар</a> </li> <li> 2.8 <a href="/book/uz/v2/Git-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8-%d0%a5%d1%83%d0%bb%d0%be%d1%81%d0%b0">Хулоса</a> </li> </ol> </li> <li class='chapter'> <h2>3. <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a2%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d2%b3%d0%b0%d2%9b%d0%b8%d0%b4%d0%b0-%d0%b8%d0%ba%d0%ba%d0%b8-%d0%be%d2%93%d0%b8%d0%b7-%d1%81%d1%9e%d0%b7">Git да тармоқланиш</a></h2> <ol> <li> 3.1 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a2%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d2%b3%d0%b0%d2%9b%d0%b8%d0%b4%d0%b0-%d0%b8%d0%ba%d0%ba%d0%b8-%d0%be%d2%93%d0%b8%d0%b7-%d1%81%d1%9e%d0%b7">Тармоқланиш ҳақида икки оғиз сўз</a> </li> <li> 3.2 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a2%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%b2%d0%b0-%d0%b1%d0%b8%d1%80%d0%bb%d0%b0%d1%88%d0%b8%d1%88-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d1%80%d0%b8">Тармоқланиш ва бирлашиш асослари</a> </li> <li> 3.3 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a2%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d1%80%d0%bd%d0%b8-%d0%b1%d0%be%d1%88%d2%9b%d0%b0%d1%80%d0%b8%d1%88">Тармоқларни бошқариш</a> </li> <li> 3.4 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%98%d1%88-%d0%b6%d0%b0%d1%80%d0%b0%d1%91%d0%bd%d0%bb%d0%b0%d1%80%d0%b8%d0%bd%d0%b8-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d1%88">Иш жараёнларини тармоқлаш</a> </li> <li> 3.5 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a3%d0%b7%d0%be%d2%9b-%d0%bc%d0%b0%d1%81%d0%be%d1%84%d0%b0%d0%b4%d0%b0%d0%b3%d0%b8-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d1%80">Узоқ масофадаги тармоқлар</a> </li> <li> 3.6 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d2%9a%d0%b0%d0%b9%d1%82%d0%b0-%d0%b0%d1%81%d0%be%d1%81%d0%bb%d0%b0%d0%bd%d0%b8%d1%88">Қайта асосланиш</a> </li> <li> 3.7 <a href="/book/uz/v2/Git-%d0%b4%d0%b0-%d1%82%d0%b0%d1%80%d0%bc%d0%be%d2%9b%d0%bb%d0%b0%d0%bd%d0%b8%d1%88-%d0%a5%d1%83%d0%bb%d0%be%d1%81%d0%b0%d0%bb%d0%b0%d1%80">Хулосалар</a> </li> </ol> </li> <li class='chapter'> <h2>4. <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-The-Protocols">Git серверда</a></h2> <ol> <li> 4.1 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-The-Protocols">The Protocols</a> </li> <li> 4.2 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Getting-Git-on-a-Server">Getting Git on a Server</a> </li> <li> 4.3 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Sizning-SSH-ochiq-public-kalitingizni-generatsiyalash">Sizning SSH ochiq (public) kalitingizni generatsiyalash</a> </li> <li> 4.4 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Setting-Up-the-Server">Setting Up the Server</a> </li> <li> 4.5 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Git-Daemon">Git Daemon</a> </li> <li> 4.6 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Smart-HTTP">Smart HTTP</a> </li> <li> 4.7 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-GitWeb">GitWeb</a> </li> <li> 4.8 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-GitLab">GitLab</a> </li> <li> 4.9 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-Third-Party-Hosted-Options">Third Party Hosted Options</a> </li> <li> 4.10 <a href="/book/uz/v2/Git-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%b4%d0%b0-%d0%a5%d1%83%d0%bb%d0%be%d1%81%d0%b0%d0%bb%d0%b0%d1%80">Хулосалар</a> </li> </ol> </li> <li class='chapter'> <h2>5. <a href="/book/uz/v2/Distributed-Git-Distributed-Workflows">Distributed Git</a></h2> <ol> <li> 5.1 <a href="/book/uz/v2/Distributed-Git-Distributed-Workflows">Distributed Workflows</a> </li> <li> 5.2 <a href="/book/uz/v2/Distributed-Git-Contributing-to-a-Project">Contributing to a Project</a> </li> <li> 5.3 <a href="/book/uz/v2/Distributed-Git-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 5.4 <a href="/book/uz/v2/Distributed-Git-Summary">Summary</a> </li> </ol> </li> </ol> </div> <div class='column-middle'> <ol class='book-toc'> <li class='chapter'> <h2>6. <a href="/book/uz/v2/GitHub-Account-Setup-and-Configuration">GitHub</a></h2> <ol> <li> 6.1 <a href="/book/uz/v2/GitHub-Account-Setup-and-Configuration">Account Setup and Configuration</a> </li> <li> 6.2 <a href="/book/uz/v2/GitHub-Contributing-to-a-Project">Contributing to a Project</a> </li> <li> 6.3 <a href="/book/uz/v2/GitHub-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 6.4 <a href="/book/uz/v2/GitHub-Managing-an-organization">Managing an organization</a> </li> <li> 6.5 <a href="/book/uz/v2/GitHub-Scripting-GitHub">Scripting GitHub</a> </li> <li> 6.6 <a href="/book/uz/v2/GitHub-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>7. <a href="/book/uz/v2/Git-Tools-Revision-Selection">Git Tools</a></h2> <ol> <li> 7.1 <a href="/book/uz/v2/Git-Tools-Revision-Selection">Revision Selection</a> </li> <li> 7.2 <a href="/book/uz/v2/Git-Tools-Interactive-Staging">Interactive Staging</a> </li> <li> 7.3 <a href="/book/uz/v2/Git-Tools-Stashing-and-Cleaning">Stashing and Cleaning</a> </li> <li> 7.4 <a href="/book/uz/v2/Git-Tools-Signing-Your-Work">Signing Your Work</a> </li> <li> 7.5 <a href="/book/uz/v2/Git-Tools-Searching">Searching</a> </li> <li> 7.6 <a href="/book/uz/v2/Git-Tools-Rewriting-History">Rewriting History</a> </li> <li> 7.7 <a href="/book/uz/v2/Git-Tools-Reset-Demystified">Reset Demystified</a> </li> <li> 7.8 <a href="/book/uz/v2/Git-Tools-Advanced-Merging">Advanced Merging</a> </li> <li> 7.9 <a href="/book/uz/v2/Git-Tools-Rerere">Rerere</a> </li> <li> 7.10 <a href="/book/uz/v2/Git-Tools-Debugging-with-Git">Debugging with Git</a> </li> <li> 7.11 <a href="/book/uz/v2/Git-Tools-Qism-modullar-Submodule">Qism modullar (Submodule)</a> </li> <li> 7.12 <a href="/book/uz/v2/Git-Tools-Bundling">Bundling</a> </li> <li> 7.13 <a href="/book/uz/v2/Git-Tools-Replace">Replace</a> </li> <li> 7.14 <a href="/book/uz/v2/Git-Tools-Credential-Storage">Credential Storage</a> </li> <li> 7.15 <a href="/book/uz/v2/Git-Tools-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>8. <a href="/book/uz/v2/Customizing-Git-Git-Configuration">Customizing Git</a></h2> <ol> <li> 8.1 <a href="/book/uz/v2/Customizing-Git-Git-Configuration">Git Configuration</a> </li> <li> 8.2 <a href="/book/uz/v2/Customizing-Git-Git-Attributes">Git Attributes</a> </li> <li> 8.3 <a href="/book/uz/v2/Customizing-Git-Git-Hooks" class="active">Git Hooks</a> </li> <li> 8.4 <a href="/book/uz/v2/Customizing-Git-An-Example-Git-Enforced-Policy">An Example Git-Enforced Policy</a> </li> <li> 8.5 <a href="/book/uz/v2/Customizing-Git-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>9. <a href="/book/uz/v2/Git-and-Other-Systems-Git-as-a-Client">Git and Other Systems</a></h2> <ol> <li> 9.1 <a href="/book/uz/v2/Git-and-Other-Systems-Git-as-a-Client">Git as a Client</a> </li> <li> 9.2 <a href="/book/uz/v2/Git-and-Other-Systems-Migrating-to-Git">Migrating to Git</a> </li> <li> 9.3 <a href="/book/uz/v2/Git-and-Other-Systems-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>10. <a href="/book/uz/v2/Git-Internals-Plumbing-and-Porcelain">Git Internals</a></h2> <ol> <li> 10.1 <a href="/book/uz/v2/Git-Internals-Plumbing-and-Porcelain">Plumbing and Porcelain</a> </li> <li> 10.2 <a href="/book/uz/v2/Git-Internals-Git-Objects">Git Objects</a> </li> <li> 10.3 <a href="/book/uz/v2/Git-Internals-Git-References">Git References</a> </li> <li> 10.4 <a href="/book/uz/v2/Git-Internals-Packfiles">Packfiles</a> </li> <li> 10.5 <a href="/book/uz/v2/Git-Internals-The-Refspec">The Refspec</a> </li> <li> 10.6 <a href="/book/uz/v2/Git-Internals-Transfer-Protocols">Transfer Protocols</a> </li> <li> 10.7 <a href="/book/uz/v2/Git-Internals-Maintenance-and-Data-Recovery">Maintenance and Data Recovery</a> </li> <li> 10.8 <a href="/book/uz/v2/Git-Internals-Environment-Variables">Environment Variables</a> </li> <li> 10.9 <a href="/book/uz/v2/Git-Internals-Summary">Summary</a> </li> </ol> </li> </ol> </div> <div class='column-right'> <ol class='book-toc'> <li class='chapter'> <h2>A1. <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Graphical-Interfaces">Appendix A: Git in Other Environments</a></h2> <ol> <li> A1.1 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Graphical-Interfaces">Graphical Interfaces</a> </li> <li> A1.2 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Visual-Studio">Git in Visual Studio</a> </li> <li> A1.3 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Eclipse">Git in Eclipse</a> </li> <li> A1.4 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Bash">Git in Bash</a> </li> <li> A1.5 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Zsh">Git in Zsh</a> </li> <li> A1.6 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Powershell">Git in Powershell</a> </li> <li> A1.7 <a href="/book/uz/v2/Appendix-A:-Git-in-Other-Environments-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>A2. <a href="/book/uz/v2/Appendix-B:-Embedding-Git-in-your-Applications-Command-line-Git">Appendix B: Embedding Git in your Applications</a></h2> <ol> <li> A2.1 <a href="/book/uz/v2/Appendix-B:-Embedding-Git-in-your-Applications-Command-line-Git">Command-line Git</a> </li> <li> A2.2 <a href="/book/uz/v2/Appendix-B:-Embedding-Git-in-your-Applications-Libgit2">Libgit2</a> </li> <li> A2.3 <a href="/book/uz/v2/Appendix-B:-Embedding-Git-in-your-Applications-JGit">JGit</a> </li> </ol> </li> <li class='chapter'> <h2>A3. <a href="/book/uz/v2/Appendix-C:-Git-Commands-Setup-and-Config">Appendix C: Git Commands</a></h2> <ol> <li> A3.1 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Setup-and-Config">Setup and Config</a> </li> <li> A3.2 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Getting-and-Creating-Projects">Getting and Creating Projects</a> </li> <li> A3.3 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Basic-Snapshotting">Basic Snapshotting</a> </li> <li> A3.4 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Branching-and-Merging">Branching and Merging</a> </li> <li> A3.5 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Sharing-and-Updating-Projects">Sharing and Updating Projects</a> </li> <li> A3.6 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Inspection-and-Comparison">Inspection and Comparison</a> </li> <li> A3.7 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Debugging">Debugging</a> </li> <li> A3.8 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Patching">Patching</a> </li> <li> A3.9 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Email">Email</a> </li> <li> A3.10 <a href="/book/uz/v2/Appendix-C:-Git-Commands-External-Systems">External Systems</a> </li> <li> A3.11 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Administration">Administration</a> </li> <li> A3.12 <a href="/book/uz/v2/Appendix-C:-Git-Commands-Plumbing-Commands">Plumbing Commands</a> </li> </ol> </li> </ol> </div> </div> </div> <span class="light" id="edition"> 2nd Edition </span> </div> <div id="main" data-pagefind-filter="category:book" data-pagefind-meta="category:Book" data-pagefind-weight="0.05" data-pagefind-body class="book edition2"> <h1>8.3 Customizing Git - Git Hooks</h1> <div> <h2 id="_git_hooks">Git Hooks</h2> <div class="paragraph"> <p> Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. You can use these hooks for all sorts of reasons</p> </div> <div class="sect3"> <h3 id="_installing_a_hook">Installing a Hook</h3> <div class="paragraph"> <p>The hooks are all stored in the <code>hooks</code> subdirectory of the Git directory. In most projects, that’s <code>.git/hooks</code>. When you initialize a new repository with <code>git init</code>, Git populates the hooks directory with a bunch of example scripts, many of which are useful by themselves; but they also document the input values of each script. All the examples are written as shell scripts, with some Perl thrown in, but any properly named executable scripts will work fine – you can write them in Ruby or Python or what have you. If you want to use the bundled hook scripts, you’ll have to rename them; their file names all end with <code>.sample</code>.</p> </div> <div class="paragraph"> <p>To enable a hook script, put a file in the <code>hooks</code> subdirectory of your Git directory that is named appropriately and is executable. From that point forward, it should be called. We’ll cover most of the major hook filenames here.</p> </div> </div> <div class="sect3"> <h3 id="_client_side_hooks">Client-Side Hooks</h3> <div class="paragraph"> <p>There are a lot of client-side hooks. This section splits them into committing-workflow hooks, e-mail-workflow scripts, and everything else.</p> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <div class="title">Note</div> </td> <td class="content"> <div class="paragraph"> <p>It’s important to note that client-side hooks are <strong>not</strong> copied when you clone a repository. If your intent with these scripts is to enforce a policy, you’ll probably want to do that on the server side; see the example in <a href="/book/uz/v2/ch00/_an_example_git_enforced_policy">An Example Git-Enforced Policy</a>.</p> </div> </td> </tr> </table> </div> <div class="sect4"> <h4 id="_committing_workflow_hooks">Committing-Workflow Hooks</h4> <div class="paragraph"> <p>The first four hooks have to do with the committing process.</p> </div> <div class="paragraph"> <p>The <code>pre-commit</code> hook is run first, before you even type in a commit message. It’s used to inspect the snapshot that’s about to be committed, to see if you’ve forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you can bypass it with <code>git commit --no-verify</code>. You can do things like check for code style (run <code>lint</code> or something equivalent), check for trailing whitespace (the default hook does exactly this), or check for appropriate documentation on new methods.</p> </div> <div class="paragraph"> <p>The <code>prepare-commit-msg</code> hook is run before the commit message editor is fired up but after the default message is created. It lets you edit the default message before the commit author sees it. This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit. This hook generally isn’t useful for normal commits; rather, it’s good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits. You may use it in conjunction with a commit template to programmatically insert information.</p> </div> <div class="paragraph"> <p>The <code>commit-msg</code> hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through. In the last section of this chapter, We’ll demonstrate using this hook to check that your commit message is conformant to a required pattern.</p> </div> <div class="paragraph"> <p>After the entire commit process is completed, the <code>post-commit</code> hook runs. It doesn’t take any parameters, but you can easily get the last commit by running <code>git log -1 HEAD</code>. Generally, this script is used for notification or something similar.</p> </div> </div> <div class="sect4"> <h4 id="_email_hooks">E-mail Workflow Hooks</h4> <div class="paragraph"> <p>You can set up three client-side hooks for an e-mail-based workflow. They’re all invoked by the <code>git am</code> command, so if you aren’t using that command in your workflow, you can safely skip to the next section. If you’re taking patches over e-mail prepared by <code>git format-patch</code>, then some of these may be helpful to you.</p> </div> <div class="paragraph"> <p>The first hook that is run is <code>applypatch-msg</code>. It takes a single argument: the name of the temporary file that contains the proposed commit message. Git aborts the patch if this script exits non-zero. You can use this to make sure a commit message is properly formatted, or to normalize the message by having the script edit it in place.</p> </div> <div class="paragraph"> <p>The next hook to run when applying patches via <code>git am</code> is <code>pre-applypatch</code>. Somewhat confusingly, it is run <em>after</em> the patch is applied but before a commit is made, so you can use it to inspect the snapshot before making the commit. You can run tests or otherwise inspect the working tree with this script. If something is missing or the tests don’t pass, exiting non-zero aborts the <code>git am</code> script without committing the patch.</p> </div> <div class="paragraph"> <p>The last hook to run during a <code>git am</code> operation is <code>post-applypatch</code>, which runs after the commit is made. You can use it to notify a group or the author of the patch you pulled in that you’ve done so. You can’t stop the patching process with this script.</p> </div> </div> <div class="sect4"> <h4 id="_other_client_hooks">Other Client Hooks</h4> <div class="paragraph"> <p>The <code>pre-rebase</code> hook runs before you rebase anything and can halt the process by exiting non-zero. You can use this hook to disallow rebasing any commits that have already been pushed. The example <code>pre-rebase</code> hook that Git installs does this, although it makes some assumptions that may not match with your workflow.</p> </div> <div class="paragraph"> <p>The <code>post-rewrite</code> hook is run by commands that replace commits, such as <code>git commit --amend</code> and <code>git rebase</code> (though not by <code>git filter-branch</code>). Its single argument is which command triggered the rewrite, and it receives a list of rewrites on <code>stdin</code>. This hook has many of the same uses as the <code>post-checkout</code> and <code>post-merge</code> hooks.</p> </div> <div class="paragraph"> <p>After you run a successful <code>git checkout</code>, the <code>post-checkout</code> hook runs; you can use it to set up your working directory properly for your project environment. This may mean moving in large binary files that you don’t want source controlled, auto-generating documentation, or something along those lines.</p> </div> <div class="paragraph"> <p>The <code>post-merge</code> hook runs after a successful <code>merge</code> command. You can use it to restore data in the working tree that Git can’t track, such as permissions data. This hook can likewise validate the presence of files external to Git control that you may want copied in when the working tree changes.</p> </div> <div class="paragraph"> <p>The <code>pre-push</code> hook runs during <code>git push</code>, after the remote refs have been updated but before any objects have been transferred. It receives the name and location of the remote as parameters, and a list of to-be-updated refs through <code>stdin</code>. You can use it to validate a set of ref updates before a push occurs (a non-zero exit code will abort the push).</p> </div> <div class="paragraph"> <p>Git occasionally does garbage collection as part of its normal operation, by invoking <code>git gc --auto</code>. The <code>pre-auto-gc</code> hook is invoked just before the garbage collection takes place, and can be used to notify you that this is happening, or to abort the collection if now isn’t a good time.</p> </div> </div> </div> <div class="sect3"> <h3 id="_server_side_hooks">Server-Side Hooks</h3> <div class="paragraph"> <p>In addition to the client-side hooks, you can use a couple of important server-side hooks as a system administrator to enforce nearly any kind of policy for your project. These scripts run before and after pushes to the server. The pre hooks can exit non-zero at any time to reject the push as well as print an error message back to the client; you can set up a push policy that’s as complex as you wish.</p> </div> <div class="sect4"> <h4 id="_pre_receive"><code>pre-receive</code></h4> <div class="paragraph"> <p>The first script to run when handling a push from a client is <code>pre-receive</code>. It takes a list of references that are being pushed from stdin; if it exits non-zero, none of them are accepted. You can use this hook to do things like make sure none of the updated references are non-fast-forwards, or to do access control for all the refs and files they’re modifying with the push.</p> </div> </div> <div class="sect4"> <h4 id="_update"><code>update</code></h4> <div class="paragraph"> <p>The <code>update</code> script is very similar to the <code>pre-receive</code> script, except that it’s run once for each branch the pusher is trying to update. If the pusher is trying to push to multiple branches, <code>pre-receive</code> runs only once, whereas update runs once per branch they’re pushing to. Instead of reading from stdin, this script takes three arguments: the name of the reference (branch), the SHA-1 that reference pointed to before the push, and the SHA-1 the user is trying to push. If the update script exits non-zero, only that reference is rejected; other references can still be updated.</p> </div> </div> <div class="sect4"> <h4 id="_post_receive"><code>post-receive</code></h4> <div class="paragraph"> <p>The <code>post-receive</code> hook runs after the entire process is completed and can be used to update other services or notify users. It takes the same stdin data as the <code>pre-receive</code> hook. Examples include e-mailing a list, notifying a continuous integration server, or updating a ticket-tracking system – you can even parse the commit messages to see if any tickets need to be opened, modified, or closed. This script can’t stop the push process, but the client doesn’t disconnect until it has completed, so be careful if you try to do anything that may take a long time.</p> </div> </div> </div> <div id="nav"><a href="/book/uz/v2/Customizing-Git-Git-Attributes">prev</a> | <a href="/book/uz/v2/Customizing-Git-An-Example-Git-Enforced-Policy">next</a></div> </div> </div> </div> </div> <footer> <div class="site-source"> <a href="/site">About this site</a><br> Patches, suggestions, and comments are welcome. </div> <div class="sfc-member"> Git is a member of <a href="/sfc">Software Freedom Conservancy</a> </div> </footer> <a href="#top" class="no-js scrollToTop" id="scrollToTop" data-label="Scroll to top"> <img src="/images/icons/chevron-up@2x.png" width="20" height="20" alt="scroll-to-top"/> </a> <script src="/js/jquery-1.7.1.min.js"></script> <script src="/js/jquery-ui-1.8.18.custom.min.js"></script> <script src="/js/jquery.defaultvalue.js"></script> <script src="/js/session.min.js"></script> <script src="/js/application.min.js"></script> </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10