More Related Content Similar to はじめてのGit (20) はじめてのGit28. その前に・・・
$ git --version
git version 1.9.5 (Apple Git-50.3)
git のコマンドが利用できるか確認する
Mac の場合
だいたい最初から使える
バージョンが古い場合はアップデートしておく
Windows の場合
だいたい最初から使えない
Git の公式サイト(http://git-scm.com/)からダウンロードしてインストール
GitBash を利用する
29. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
30. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
32. サーバに接続
①ディレクトリ「test.git」作成
②ディレクトリ「test.git」に移動
③リポジトリ作成
-- bare : 作業ディレクトリを持たないリポジトリ(ベアリポジトリ) を作成
--shaed : リポジトリに対するグループ書き込み権を追加
実行後「test.git」ディレクトリが作成され、Git の管理ファイル(HEAD他)が作成される
$ mkdir test.git
$ cd test.git
$ git init --bare --shared
Initialized empty shared Git repository in /
yourpath/gittest/test.git/
サーバー
※サーバへの接続手順は割愛します
※yourpath は環境によって異なります
Point
サーバにリモートリポジトリを作成する
手順(例)
33. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
34. $ git clone https://username@yourserver/path/test.git
Cloning into 'test2'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done
※username他 は環境によって異なります
リモートリポジトリからローカルリポジトリに複製する
①複製する
手順(例)
36. 作成するディレクトリ名を指定する
$ git clone <リモートリポジトリのURL> <作成するディレクトリ>
リモートリポジトリのURL(接続方式)を変更する
$ git clone http://<サーバアドレス>/<Gitリポジトリのパス>
$ git clone git://<サーバアドレス>/<Gitリポジトリのパス>
$ git clone ssh://[ユーザ名@]<サーバアドレス>/<Gitリポジトリのパス>
$ git clone file://<Gitリポジトリのパス>
$ git clone <Gitリポジトリのパス>
$ git clone --depth 1 <リモートリポジトリのURL>
最新の更新履歴だけ取得する
http で接続
git で接続
ssh で接続
ローカルに接続
ローカルに接続
37. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
40. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
41. 状態【修正済】
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
状態【ステージ済】
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
42. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
43. ①ファイル「test.txt」を更新 - ②コミットする - ③コミットログを確認する
ファイルを更新してコミットログを確認
手順(例)
$ echo ’add line 2nd’ >> test.txt
$ git commit -am ‘2回目のコミット’
$ git log
commit 17ab37226496e2e0ed61454abcd1c06848fcd473
Author: xxxxxx
Date: Fri Jul 3 20:14:28 2015 +0900
2回目のコミット
commit db4c03dee2e6dabcb81dae724e3c9e0adaa0e3fb
Author: xxxxxxx
Date: Fri Jul 3 19:26:12 2015 +0900
はじめてのコミット
45. コミットを1行ずつ表示する
$ git log --oneline
17ab372 2回目のコミット
db4c03d はじめてのコミット
コミット毎の差分を表示する
$ git log --p
<<省略>>
diff --git a/test.txt b/test.txt
index aa39060..2096694 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
newfile
+add line 2nd
46. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
49. 過去にコミットした内容と比較
$ git log --oneline
17ab372 2回目のコミット
db4c03d はじめてのコミット
$ git diff db4c03d
diff --git a/test.txt b/test.txt
index aa39060..1d641a9 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,3 @@
newfile
+add line 2nd
+add line 3rd
①コミットログを表示 - ②比較したいコミットIDを指定して比較 手順(例)
50. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
55. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
56. リモートリポジトリにプッシュ(push)する
①リモートリポジトリを登録 - ②リモートリポジトリへpushする
手順(例)
$ git remote add origin https://username@yourserver/path/test.git
$ git push origin master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 483 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://username@yourserver/path/test.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
※username他 は環境によって異なります
※複製(git clone)でローカルリポジトリを
作成した場合は既に出来ているので不要
57. Git の基本コマンド
① 環境設定編
git init : リポジトリを作成する
git clone : リポジトリを複製する
② ローカル操作編
git add : ステージに移動する(ステージング)
git commit : コミットする
git status : 状態を確認する
git log : 更新(コミット)履歴を確認する
git diff : 状態を比較する
git checkout : 状態を戻す
③ リモート操作編
git push : リモートリポジトリにプッシュする
git pull : リモートリポジトリからプルする
58. リモートリポジトリから(pull)する
①リモートリポジトリから pull する
手順(例)
$ git pull
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From https://username@yourserver/path/test.git
835b409..52c3c38 master -> origin/master
Updating 835b409..52c3c38
Fast-forward
test.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
※username他 は環境によって異なります