154 lines
16 KiB
Markdown
154 lines
16 KiB
Markdown
---
|
|
title: gitのチュートリアル
|
|
author: kazu634
|
|
date: 2009-06-02
|
|
wordtwit_post_info:
|
|
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4631;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
|
|
categories:
|
|
- git
|
|
|
|
---
|
|
<div class="section">
|
|
<p>
|
|
『<a href="http://d.hatena.ne.jp/asin/477413838X" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/477413838X', 'WEB+DB PRESS Vol.50');">WEB+DB PRESS Vol.50</a>』の特集を見ながらまとめてみるよ:
|
|
</p>
|
|
|
|
<h4>
|
|
初期設定
|
|
</h4>
|
|
|
|
<p>
|
|
こんな感じでgitに自分の名前とメールアドレスなどを教えて上げるといい。
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
<span class="synComment">#!/bin/bash</span>
|
|
<span class="synComment"># Name</span>
|
|
git config <span class="synSpecial">--global</span> user.name <span class="synStatement">"</span><span class="synConstant">Kazuhiro MUSASHI</span><span class="synStatement">"</span>
|
|
<span class="synComment"># E-Mail</span>
|
|
git config <span class="synSpecial">--global</span> user.email <span class="synStatement">"</span><span class="synConstant">simoom634@yahoo.co.jp</span><span class="synStatement">"</span>
|
|
<span class="synComment"># Colour</span>
|
|
git config <span class="synSpecial">--global</span> color.ui auto
|
|
<span class="synComment"># Ignoring files</span>
|
|
<span class="synComment"># http://ogijun.g.hatena.ne.jp/secondlife/20080306/1204774860</span>
|
|
git config <span class="synSpecial">--global</span> <span class="synSpecial">--add</span> core.excludesfile <span class="synStatement">"</span><span class="synPreProc">$HOME</span><span class="synConstant">/.gitignore</span><span class="synStatement">"</span>
|
|
</pre>
|
|
|
|
<h4>
|
|
リポジトリの初期化
|
|
</h4>
|
|
|
|
<pre class="syntax-highlight">
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">523</span><span class="synStatement">]</span> $: git init
|
|
Initialized empty Git repository <span class="synError">in</span> /Users/simoom634/working/cgi/.git/
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">524</span><span class="synStatement">]</span> $: ll
|
|
total <span class="synConstant">8</span>
|
|
drwxr-xr-x <span class="synConstant">3</span> simoom634 staff <span class="synConstant">136</span> <span class="synConstant">6</span> <span class="synConstant">2</span> <span class="synConstant">22</span>:<span class="synConstant">47</span> ./
|
|
drwxr-xr-x <span class="synConstant">10</span> simoom634 staff <span class="synConstant">374</span> <span class="synConstant">6</span> <span class="synConstant">2</span> <span class="synConstant">22</span>:<span class="synConstant">36</span> ../
|
|
drwxr-xr-x <span class="synConstant">7</span> simoom634 staff <span class="synConstant">340</span> <span class="synConstant">6</span> <span class="synConstant">2</span> <span class="synConstant">22</span>:<span class="synConstant">47</span> .git/
|
|
-rw-<span class="synStatement">r</span>--<span class="synStatement">r</span>-- <span class="synConstant">1</span> simoom634 staff <span class="synConstant">89</span> <span class="synConstant">6</span> <span class="synConstant">2</span> <span class="synConstant">22</span>:<span class="synConstant">47</span> weekday.pl
|
|
</pre>
|
|
|
|
<h4>
|
|
最初のコミット
|
|
</h4>
|
|
|
|
<p>
|
|
ワークツリーの全てのファイルの今の状態を記録することにします:
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">527</span><span class="synStatement">]</span> $: git add .
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">528</span><span class="synStatement">]</span> $: <span class="synStatement">ls</span>
|
|
weekday.pl
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">529</span><span class="synStatement">]</span> $: git commit <span class="synSpecial">-m</span> <span class="synStatement">"</span><span class="synConstant">Initial Commit</span><span class="synStatement">"</span>
|
|
Created initial commit 89d0eeb: Initial Commit
|
|
<span class="synConstant">1</span> files changed, <span class="synConstant">8</span> insertions<span class="synStatement">(</span>+<span class="synStatement">)</span>, <span class="synConstant"></span> deletions<span class="synStatement">(</span>-<span class="synStatement">)</span>
|
|
create mode <span class="synConstant">100644</span> weekday.pl
|
|
</pre>
|
|
|
|
<ul>
|
|
<li>
|
|
git add .: 現在のディレクトリ以下すべてのファイルの状態を記録したい
|
|
</li>
|
|
<li>
|
|
git commit: コミットの作成
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>
|
|
二度目のコミット
|
|
</h4>
|
|
|
|
<p>
|
|
git commitしてから、管理対象のファイルを編集します。そうしてからgitのレポジトリとのdiffをまず撮ってみます。そうしてから、コミットしてみる:
|
|
</p>
|
|
|
|
<pre class="syntax-highlight">
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">539</span><span class="synStatement">]</span> $: git diff
|
|
diff <span class="synSpecial">--git</span> a/weekday.pl b/weekday.pl
|
|
index fc3b11f..0a9115d <span class="synConstant">100644</span>
|
|
--- a/weekday.pl
|
|
+++ b/weekday.pl
|
|
@@ <span class="synConstant">-2</span>,<span class="synConstant">7</span> <span class="synSpecial">+2</span>,<span class="synConstant">22</span> @@
|
|
use strict<span class="synStatement">;</span>
|
|
use warnings<span class="synStatement">;</span>
|
|
-use Data::Dumper<span class="synStatement">;</span>
|
|
+use CGI<span class="synStatement">;</span>
|
|
+use Time::Local<span class="synStatement">;</span>
|
|
<span class="synComment"> # === Main part ===</span>
|
|
+my <span class="synPreProc">$q</span> <span class="synStatement">=</span> new CGI<span class="synStatement">;</span>
|
|
<span class="synComment">+# クエリから年と月を得る</span>
|
|
+my <span class="synPreProc">$year</span> <span class="synStatement">=</span> <span class="synPreProc">$q</span>-<span class="synStatement">></span>param<span class="synStatement">('</span><span class="synConstant">year</span><span class="synStatement">');</span>
|
|
+my <span class="synPreProc">$month</span> <span class="synStatement">=</span> <span class="synPreProc">$q</span>-<span class="synStatement">></span>param<span class="synStatement">('</span><span class="synConstant">month</span><span class="synStatement">');</span>
|
|
+
|
|
<span class="synComment">+# 指定された月の1日を得る</span>
|
|
+my <span class="synPreProc">$firstday</span> <span class="synStatement">=</span> timelocal<span class="synStatement">(</span><span class="synConstant"></span>, <span class="synConstant"></span>, <span class="synConstant"></span>, <span class="synConstant">1</span>, <span class="synPreProc">$month</span> - <span class="synConstant">1</span>, <span class="synPreProc">$year</span> - <span class="synConstant">1900</span><span class="synStatement">);</span>
|
|
+
|
|
<span class="synComment">+# その年の曜日を得る</span>
|
|
+my <span class="synStatement">(</span><span class="synPreProc">$n_sec</span>, <span class="synPreProc">$n_min</span>, <span class="synPreProc">$n_hour</span>, <span class="synPreProc">$n_day</span>, <span class="synPreProc">$n_mon</span>, <span class="synPreProc">$n_year</span>, <span class="synPreProc">$w_day</span><span class="synStatement">)</span> <span class="synStatement">=</span> localtime<span class="synStatement">(</span><span class="synPreProc">$firstday</span><span class="synStatement">);</span>
|
|
+my <span class="synPreProc">$wdaystr</span> <span class="synStatement">=</span> <span class="synStatement">('</span><span class="synConstant">Sun</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Mon</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Tue</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Wed</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Thu</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Fri</span><span class="synStatement">'</span>, <span class="synStatement">'</span><span class="synConstant">Sat</span><span class="synStatement">')[</span><span class="synPreProc">$w_day</span><span class="synStatement">];</span>
|
|
+
|
|
+<span class="synStatement">print("</span><span class="synConstant">Content-type: text/html; char-set=utf-8</span><span class="synSpecial">\n\n</span><span class="synStatement">");</span>
|
|
+<span class="synStatement">print("</span><span class="synPreProc">$year</span><span class="synSpecial">年</span><span class="synPreProc">$month</span><span class="synSpecial">月は</span><span class="synPreProc">$wdaystr</span><span class="synSpecial">から始まります。\n</span><span class="synStatement">");</span>
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">540</span><span class="synStatement">]</span> $: git add weekday.pl
|
|
~/working/cgi on simoom634 <span class="synStatement">[</span><span class="synConstant">541</span><span class="synStatement">]</span> $: git commit
|
|
Created commit b92fda4: Sample Scriptを入力
|
|
<span class="synConstant">1</span> files changed, <span class="synConstant">16</span> insertions<span class="synStatement">(</span>+<span class="synStatement">)</span>, <span class="synConstant">1</span> deletions<span class="synStatement">(</span>-<span class="synStatement">)</span>
|
|
</pre>
|
|
|
|
<div class="hatena-asin-detail">
|
|
<a href="http://www.amazon.co.jp/dp/477413838X/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/477413838X/?tag=hatena_st1-22&ascsubtag=d-7ibv', '');"><img src="https://images-na.ssl-images-amazon.com/images/I/61Co2FMWsRL._SL160_.jpg" class="hatena-asin-detail-image" alt="WEB+DB PRESS Vol.50" title="WEB+DB PRESS Vol.50" /></a></p>
|
|
|
|
<div class="hatena-asin-detail-info">
|
|
<p class="hatena-asin-detail-title">
|
|
<a href="http://www.amazon.co.jp/dp/477413838X/?tag=hatena_st1-22&ascsubtag=d-7ibv" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazon.co.jp/dp/477413838X/?tag=hatena_st1-22&ascsubtag=d-7ibv', 'WEB+DB PRESS Vol.50');">WEB+DB PRESS Vol.50</a>
|
|
</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">作者:</span> <a href="http://d.hatena.ne.jp/keyword/%BF%F9%BB%B3%B5%AE%BE%CF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%BF%F9%BB%B3%B5%AE%BE%CF', '杉山貴章');" class="keyword">杉山貴章</a>,<a href="http://d.hatena.ne.jp/keyword/%B1%A9%C0%B8%BE%CF%CD%CE" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B1%A9%C0%B8%BE%CF%CD%CE', '羽生章洋');" class="keyword">羽生章洋</a>,<a href="http://d.hatena.ne.jp/keyword/%C0%EE%B8%FD%B9%CC%B2%F0" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C0%EE%B8%FD%B9%CC%B2%F0', '川口耕介');" class="keyword">川口耕介</a>,<a href="http://d.hatena.ne.jp/keyword/%C0%C4%CC%DA%CC%F7" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C0%C4%CC%DA%CC%F7', '青木靖');" class="keyword">青木靖</a>,<a href="http://d.hatena.ne.jp/keyword/%C4%E1%B2%AC%C4%BE%CC%E9" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C4%E1%B2%AC%C4%BE%CC%E9', '鶴岡直也');" class="keyword">鶴岡直也</a>,<a href="http://d.hatena.ne.jp/keyword/%C4%B9%CC%EE%B2%ED%B9%AD" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C4%B9%CC%EE%B2%ED%B9%AD', '長野雅広');" class="keyword">長野雅広</a>,<a href="http://d.hatena.ne.jp/keyword/%BF%B9%C5%C4%C1%CF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%BF%B9%C5%C4%C1%CF', '森田創');" class="keyword">森田創</a>,<a href="http://d.hatena.ne.jp/keyword/%B0%CB%C6%A3%C4%BE%CC%E9" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B0%CB%C6%A3%C4%BE%CC%E9', '伊藤直也');" class="keyword">伊藤直也</a>,<a href="http://d.hatena.ne.jp/keyword/%C9%F0%BC%D4%BE%BD%B5%AA" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%C9%F0%BC%D4%BE%BD%B5%AA', '武者晶紀');" class="keyword">武者晶紀</a>,<a href="http://d.hatena.ne.jp/keyword/%A5%DF%A5%C3%A5%AF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%DF%A5%C3%A5%AF', 'ミック');" class="keyword">ミック</a>,<a href="http://d.hatena.ne.jp/keyword/%B9%E2%CE%D3%C5%AF" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B9%E2%CE%D3%C5%AF', '高林哲');" class="keyword">高林哲</a>,<a href="http://d.hatena.ne.jp/keyword/%B7%AA%B8%B6%B7%E6%B5%FD" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B7%AA%B8%B6%B7%E6%B5%FD', '栗原傑享');" class="keyword">栗原傑享</a>,<a href="http://d.hatena.ne.jp/keyword/%CA%C6%CE%D3%C0%B5%CC%C0" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%CA%C6%CE%D3%C0%B5%CC%C0', '米林正明');" class="keyword">米林正明</a>,<a href="http://d.hatena.ne.jp/keyword/%BE%AE%BB%F4%C3%C6" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%BE%AE%BB%F4%C3%C6', '小飼弾');" class="keyword">小飼弾</a>,<a href="http://d.hatena.ne.jp/keyword/%B3%D1%C5%C4%C4%BE%B9%D4" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B3%D1%C5%C4%C4%BE%B9%D4', '角田直行');" class="keyword">角田直行</a>,<a href="http://d.hatena.ne.jp/keyword/%B6%B6%CB%DC%C0%B5%C6%C1" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B6%B6%CB%DC%C0%B5%C6%C1', '橋本正徳');" class="keyword">橋本正徳</a>,<a href="http://d.hatena.ne.jp/keyword/%A4%CF%A4%DE%A4%C1%A4%E42" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A4%CF%A4%DE%A4%C1%A4%E42', 'はまちや2');" class="keyword">はまちや2</a>,<a href="http://d.hatena.ne.jp/keyword/%B5%D7%CB%F6%CE%B4%CD%B5" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B5%D7%CB%F6%CE%B4%CD%B5', '久末隆裕');" class="keyword">久末隆裕</a>,<a href="http://d.hatena.ne.jp/keyword/Junio%20C%20Hamano" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/Junio%20C%20Hamano', 'Junio C Hamano');" class="keyword">Junio C Hamano</a>,<a href="http://d.hatena.ne.jp/keyword/%A5%B0%A5%CB%A5%E3%A5%E9%A4%AF%A4%F3" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A5%B0%A5%CB%A5%E3%A5%E9%A4%AF%A4%F3', 'グニャラくん');" class="keyword">グニャラくん</a>,<a href="http://d.hatena.ne.jp/keyword/%A4%E4%A4%DE%A4%C0%A4%A2%A4%AD%A4%E9" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%A4%E4%A4%DE%A4%C0%A4%A2%A4%AD%A4%E9', 'やまだあきら');" class="keyword">やまだあきら</a>,<a href="http://d.hatena.ne.jp/keyword/WEB%2BDB%20PRESS%CA%D4%BD%B8%C9%F4" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/WEB%2BDB%20PRESS%CA%D4%BD%B8%C9%F4', 'WEB+DB PRESS編集部');" class="keyword">WEB+DB PRESS編集部</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">出版社/メーカー:</span> <a href="http://d.hatena.ne.jp/keyword/%B5%BB%BD%D1%C9%BE%CF%C0%BC%D2" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/keyword/%B5%BB%BD%D1%C9%BE%CF%C0%BC%D2', '技術評論社');" class="keyword">技術評論社</a>
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">発売日:</span> 2009/04/24
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">メディア:</span> 大型本
|
|
</li>
|
|
<li>
|
|
<span class="hatena-asin-detail-label">購入</span>: 24人 <span class="hatena-asin-detail-label">クリック</span>: 235回
|
|
</li>
|
|
<li>
|
|
<a href="http://d.hatena.ne.jp/asin/477413838X" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/asin/477413838X', 'この商品を含むブログ (95件) を見る');" target="_blank">この商品を含むブログ (95件) を見る</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="hatena-asin-detail-foot">
|
|
</div>
|
|
</div>
|
|
</div>
|