Git 勉強会 #01
今回の目標• Git が何かわかる• Git の基本的な使い方がわかる• Git の内部構造を知って、動作のイメージがわかる
Git とは何か?• 分散型バージョン管理システム(Distributed version control)
バージョン管理システム?• ファイルの変更履歴の管理を行う。• ファイルの変更履歴をみんなで共有。• Git 以外では CVS, Subversion などがある。
分散?• 分散型バージョン管理システムでは、複数のレポジトリが存在し、それぞれで変更内容の管理を行う。• レポジトリ間で同期することで変更内容を共有することができる。• CVS などとは違いサーバにレポジトリがなくても利用できるため簡単にはじめられ、ネットワークがつながっていなくても利用できる。• レポジトリごとに変更内容の管理を行うので、実験的な変更など他者と共有したくない変更の管理も簡単である。
Git 使い方• 初期設定 ( 名前、メール設定 )
• git config --global user.name "Your Name”
• git config --global user.email [email protected]
レポジトリ作成• レポジトリ用のディレクトリ作成
• mkdir gittest
• cd gittest
• レポジトリを初期化• git init
コミット• コミットするファイル作成
• echo "hello world" > hello.txt
• Git にファイルを登録• git add hello.txt
• Git にコミット• git commit -m "Add hello.txt"
履歴確認• 履歴確認
• git log
ブランチ• master ブランチから新しい new-file ブランチを作成
(master はデフォルトのブランチ )• git checkout master -b new-file
• new-file ブランチ上でファイル追加• echo "Brave New World" > newworld.txt
• git add newworld.txt
• git commit -m "Add newworld.txt"
マージ• master ブランチに new-file ブランチをマージ
• git checkout master
• git merge new-file
Git 内部構造• Git はオブジェクトストレージ。• Blob, Tree, Commit, Tag の4つのオブジェクトを管理• オブジェクト内容から SHA1 のハッシュ値をオブジェクトの一意キーになる。• ブランチなどはオブジェクトへの参照で表される。• レポジトリ内の .git ディレクトリに保存される
Blob
SHA1 : 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
hello world
ファイル名 : hello.txtファイルの内容を保持する
Tree
100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt040000 tree a7328a128a47e4ac172f61d055403b32a189b772 subdir
ディレクトリ構成を保持するBlob, Tree の情報を含みます。
SHA1: 68aba62e560c0ebc3396e8ae9335232cd93a3f60
Commit
tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60author Your Name <[email protected]> 1446829094 +0900committer Your Name <[email protected]> 1446829094 +0900
Add hello.txt
コミットを表す。Tree へ参照、親となる Commit の参照、メッセージなどを含む
SHA1: ea30e75531083ef416eb90af8528d9c2ed254ed9
変更履歴
commit
commit commit
commitHEAD
ブランチ
変更履歴はコミットをノード、親となる Commit への参照をエッジとしたグラフになる
質問タイム
Recommended