{"id":364,"date":"2017-05-15T08:46:31","date_gmt":"2017-05-15T08:46:31","guid":{"rendered":"http:\/\/imalogic.com\/blog\/?p=364"},"modified":"2017-05-15T13:39:27","modified_gmt":"2017-05-15T13:39:27","slug":"le-petit-guide-du-git","status":"publish","type":"post","link":"https:\/\/imalogic.com\/blog\/2017\/05\/15\/le-petit-guide-du-git\/","title":{"rendered":"Le Petit Guide Du Git"},"content":{"rendered":"<body><p><\/p>\n<h1 id=\"wmd-preview-section-13\" class=\"wmd-preview-section preview-content\" style=\"text-align: left;\">Github<\/h1>\n<h2 id=\"wmd-preview-section-14\" class=\"wmd-preview-section preview-content\">Configuration<a href=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"378\" data-permalink=\"https:\/\/imalogic.com\/blog\/2017\/05\/15\/le-petit-guide-du-git\/attachment\/2600\/\" data-orig-file=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?fit=512%2C512&amp;ssl=1\" data-orig-size=\"512,512\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2600\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?fit=512%2C512&amp;ssl=1\" class=\"wp-image-378 alignright\" src=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?resize=225%2C225&#038;ssl=1\" alt=\"\" width=\"225\" height=\"225\" loading=\"lazy\" srcset=\"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?w=512&amp;ssl=1 512w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/h2>\n<p class=\"wmd-preview-section preview-content\">Identity Name<\/p>\n<div id=\"wmd-preview-section-15\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git config --global user.name <span class=\"hljs-string\">\"unix\"<\/span><\/code><\/pre>\n<p>Identity Email<\/p>\n<\/div>\n<div id=\"wmd-preview-section-16\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git config --global user.email <span class=\"hljs-string\">\"unix@imalogic.com\"<\/span><\/code><\/pre>\n<p>Editor Tool<\/p>\n<\/div>\n<div id=\"wmd-preview-section-17\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs mel\">$ git config --<span class=\"hljs-keyword\">global<\/span> core.<span class=\"hljs-keyword\">editor<\/span> subl<\/code><\/pre>\n<p>Diff Tool<\/p>\n<\/div>\n<div id=\"wmd-preview-section-18\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">config<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">global<\/span> <span class=\"hljs-comment\">merge<\/span><span class=\"hljs-string\">.<\/span><span class=\"hljs-comment\">tool<\/span> <span class=\"hljs-comment\">filemerge<\/span><\/code><\/pre>\n<p>Liste des globals<\/p>\n<\/div>\n<div id=\"wmd-preview-section-19\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">config<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">list<\/span><\/code><\/pre>\n<\/div>\n<div id=\"wmd-preview-section-20\" class=\"wmd-preview-section preview-content\">\n<h2 id=\"principales-commandes\">Principales commandes<\/h2>\n<p>Status des fichiers<\/p>\n<\/div>\n<div id=\"wmd-preview-section-21\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git status<\/code><\/pre>\n<p>Lister les branchs<\/p>\n<\/div>\n<div id=\"wmd-preview-section-22\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git branch<\/code><\/pre>\n<p><code>*<\/code>sur la branche courante.<\/p>\n<p>Cr\u00e9er une branch<\/p>\n<\/div>\n<div id=\"wmd-preview-section-23\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git branch nom_de_ma_branch<\/code><\/pre>\n<p>Changer de branch<\/p>\n<\/div>\n<div id=\"wmd-preview-section-24\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git checkout nom_de_ma_branch<\/code><\/pre>\n<p>Premier commit<\/p>\n<\/div>\n<div id=\"wmd-preview-section-25\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git add .\r\n<span class=\"hljs-variable\">$ <\/span>git commit - m <span class=\"hljs-string\">\"initial commit\"<\/span><\/code><\/pre>\n<p>Commit suivant<\/p>\n<\/div>\n<div id=\"wmd-preview-section-26\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git add chemin_vers_mon_fichier\r\n<span class=\"hljs-variable\">$ <\/span>git commit -m <span class=\"hljs-string\">\"message du commit\"<\/span><\/code><\/pre>\n<p>Annuler le dernier commit et modifs<\/p>\n<\/div>\n<div id=\"wmd-preview-section-27\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">reset<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">hard<\/span> <span class=\"hljs-comment\">md5_commit<\/span>\r\n<span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">push<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">force<\/span><\/code><\/pre>\n<p>Mettre \u00e0 jour le d\u00e9p\u00f4t local<\/p>\n<\/div>\n<div id=\"wmd-preview-section-28\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git pull<\/code><\/pre>\n<p>Envoyer ses commits vers le d\u00e9p\u00f4t distant<\/p>\n<\/div>\n<div id=\"wmd-preview-section-29\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git push<\/code><\/pre>\n<p>Supprimer un fichier du r\u00e9pertoire de travail et de l\u2019index<\/p>\n<\/div>\n<div id=\"wmd-preview-section-30\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git rm nom_du_fichier<\/code><\/pre>\n<p>Supprimer un fichier de l\u2019index<\/p>\n<\/div>\n<div id=\"wmd-preview-section-31\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">rmg<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">cached<\/span> <span class=\"hljs-comment\">nom_du_fichier<\/span><\/code><\/pre>\n<\/div>\n<div id=\"wmd-preview-section-32\" class=\"wmd-preview-section preview-content\">\n<h2 id=\"diff\">Diff<\/h2>\n<p>Affiche la diff\u00e9rence entre le contenu du dernier commit et celui du r\u00e9pertoire de travail. Cela correspond \u00e0 ce qui serait commit\u00e9 par git commit -a.<\/p>\n<\/div>\n<div id=\"wmd-preview-section-33\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git diff <span class=\"hljs-constant\">HEAD<\/span><\/code><\/pre>\n<p>Affiche la diff\u00e9rence entre le contenu point\u00e9 par A et celui point\u00e9 par B.<\/p>\n<\/div>\n<div id=\"wmd-preview-section-34\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git diff <span class=\"hljs-constant\">A<\/span> <span class=\"hljs-constant\">B<\/span><\/code><\/pre>\n<p>Diff entre un dossier pr\u00e9sent sur deux branches<\/p>\n<\/div>\n<div id=\"wmd-preview-section-35\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git diff master..<span class=\"hljs-constant\">MA_BRANCH<\/span> chemin\/vers\/mon_dossier<\/code><\/pre>\n<\/div>\n<div id=\"wmd-preview-section-36\" class=\"wmd-preview-section preview-content\">\n<h2 id=\"log\">Log<\/h2>\n<\/div>\n<div id=\"wmd-preview-section-37\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git log\r\n<span class=\"hljs-comment\"># Affiche X derniers commits<\/span>\r\n<span class=\"hljs-variable\">$ <\/span>git log -n <span class=\"hljs-constant\">X<\/span>\r\n<span class=\"hljs-comment\"># Affiche un ensemble de commits par date<\/span>\r\n<span class=\"hljs-variable\">$ <\/span>git log --since=date --<span class=\"hljs-keyword\">until<\/span>=date<\/code><\/pre>\n<p>Repre\u0301sentation de l\u2019historique a\u0300 partir de HEAD (commit \/ branch)<\/p>\n<\/div>\n<div id=\"wmd-preview-section-38\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">log<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">oneline<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">graph<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">decorate<\/span><\/code><\/pre>\n<p>Repre\u0301sentation de l\u2019historique a\u0300 partir d\u2019un fichier (commit \/ branch)<\/p>\n<\/div>\n<div id=\"wmd-preview-section-39\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">log<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">oneline<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">graph<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">decorate<\/span> <span class=\"hljs-comment\">nom_du_fichier<\/span><\/code><\/pre>\n<\/div>\n<div id=\"wmd-preview-section-40\" class=\"wmd-preview-section preview-content\">\n<h2 id=\"annuler-commits-soft\">Annuler commits (soft)<\/h2>\n<p>Seul le commit est retir\u00e9 de Git ; vos fichiers, eux, restent modifi\u00e9s. Vous pouvez alors \u00e0 nouveau changer vos fichiers si besoin est et refaire un commit.<\/p>\n<p>Annuler le dernier commit<\/p>\n<\/div>\n<div id=\"wmd-preview-section-41\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git reset <span class=\"hljs-constant\">HEAD<\/span>^<\/code><\/pre>\n<p>Pour indiquer \u00e0 quel commit on souhaite revenir, il existe plusieurs notations :<\/p>\n<ul>\n<li>HEAD : dernier commit ;<\/li>\n<li>HEAD^ : avant-dernier commit ;<\/li>\n<li>HEAD^^ : avant-avant-dernier commit ;<\/li>\n<li>HEAD~2 : avant-avant-dernier commit (notation \u00e9quivalente) ;<\/li>\n<li>d6d98923868578a7f38dea79833b56d0326fcba1 : indique un num\u00e9ro de commit pr\u00e9cis ;<\/li>\n<\/ul>\n<\/div>\n<div id=\"wmd-preview-section-42\" class=\"wmd-preview-section preview-content\">\n<h2 id=\"annuler-commits-hard\">Annuler commits (hard)<\/h2>\n<p>Si vous voulez annuler votre dernier commit et les changements effectu\u00e9s dans les fichiers, il faut faire un reset hard. <em>Cela annulera sans confirmation tout votre travail !<\/em><\/p>\n<p>Annuler les commits et perdre tous les changements<\/p>\n<\/div>\n<div id=\"wmd-preview-section-43\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">reset<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span><span class=\"hljs-comment\">hard<\/span> <span class=\"hljs-comment\">HEAD^<\/span><\/code><\/pre>\n<p><em>Annuler les modifications d\u2019un fichier avant un commit<\/em><\/p>\n<p>Si vous avez modifi\u00e9 plusieurs fichiers mais que vous n\u2019avez pas encore envoy\u00e9 le commit et que vous voulez restaurer un fichier tel qu\u2019il \u00e9tait au dernier commit :<\/p>\n<\/div>\n<div id=\"wmd-preview-section-44\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs ruby\"><span class=\"hljs-variable\">$ <\/span>git checkout nom_du_fichier<\/code><\/pre>\n<p><em>Annuler\/Supprimer un fichier avant un commit<\/em><\/p>\n<p>Supposer que vous venez d\u2019ajouter un fichier \u00e0 Git avec <code>git add<\/code> et que vous vous appr\u00eatez \u00e0 le \u00ab commiter \u00bb. Cependant, vous vous rendez compte que ce fichier est une mauvaise id\u00e9e et vous voulez annuler votre <code>git add<\/code>.<\/p>\n<p>Il est possible de retirer un fichier qui avait \u00e9t\u00e9 ajout\u00e9 pour \u00eatre \u00ab commit\u00e9 \u00bb en proc\u00e9dant comme suit :<\/p>\n<\/div>\n<div id=\"wmd-preview-section-45\" class=\"wmd-preview-section preview-content\">\n<pre class=\"prettyprint\"><code class=\"language-shell hljs brainfuck\"><span class=\"hljs-comment\">$<\/span> <span class=\"hljs-comment\">git<\/span> <span class=\"hljs-comment\">reset<\/span> <span class=\"hljs-comment\">HEAD<\/span> <span class=\"hljs-literal\">-<\/span><span class=\"hljs-literal\">-<\/span> <span class=\"hljs-comment\">nom_du_fichier_a_supprimer<\/span><\/code><\/pre>\n<\/div>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>Github Configuration Identity Name $ git config &#8211;global user.name &#8220;unix&#8221; Identity Email $ git config &#8211;global user.email &#8220;unix@imalogic.com&#8221; Editor Tool<\/p>\n","protected":false},"author":1,"featured_media":378,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[],"class_list":["post-364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/imalogic.com\/blog\/wp-content\/uploads\/2017\/05\/2600.png?fit=512%2C512&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8J21V-5S","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/comments?post=364"}],"version-history":[{"count":1,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":379,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/posts\/364\/revisions\/379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/media\/378"}],"wp:attachment":[{"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/media?parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/categories?post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imalogic.com\/blog\/wp-json\/wp\/v2\/tags?post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}