仕組みから学ぶGitハンズオン

18.8K Views

July 12, 25

スライド概要

2025/7/12 仕組みから学ぶGitハンズオン
https://ibukalab.connpass.com/event/358238/

profile-image

SeeedKKの中の人。Microsoft MVP for Internet of Things。

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

(ダウンロード不可)

関連スライド

各ページのテキスト
1.

仕組みから学ぶGitハンズオン 202 5/7/ 12 仕組 みから 学ぶGi tハンズオ ン 202 5/7/ 14 改訂 202 5/7/ 18 ma cOS追加 MATSUOKA Takashi @matsujirushi12

2.

MATSUOKA Takashi @matsujirushi12 2017~ MVP for Windows Development 2020~ for Microsoft Azure 2022~ for Internet of Things 1991年大手メーカーに入社し、 工場の自動化や情報システム の開発、運用に従事。2017年8 月、Seeed株式会社設立時に 転職。組み込みデバイスの開 発環境整備やライブラリ開発 を担当。 書籍 雑誌 YouTube 「e」3つ

3.

LAB0 はじめに

4.

当イベントは、単にGitの操作を学ぶのではなく、変更履歴やブランチ管理などの Git機能がどのように実装されているのか という仕組みを理解した上で、実際の 操作方法を学ぶハンズオンです。 どのように保存されているのか どのように操作するのか

5.

2024年7月号 別冊付録 Git&GitHubをはじめる本 2025年1月号 第1回 Gitが情報を記録する仕組み 2025年2月号 第2回 タグとブランチ戦略 2025年5月号 第3回 変更履歴の表示と検索 2025年7月号 第4回 リモート機能プッシュ/フェッチ/プルを使ってみる 2025年8月号 第5回 巨大プロジェクトの分割に便利なサブモジュール機能 Pro Git https://git-scm.com/book/ja/v2 ゼロから学ぶGit/GitHub Git/GitHubをもっと知りたい!いまさら聞けない実用セミナー @ALGYAN https://www.youtube.com/watch?v=FNDqHFAsvuQ

6.

LAB1 リポジトリ (Repository)

7.

LAB1 ファイルの変更を記録する 変更後 変更前 ディレクトリ ファイル ディレクトリ ファイル 変更 Work Tree 記録 Repository Commit 記録 Commit スナップショット スナップショット

8.

LAB1 ファイルの変更を記録する 現在の Work Treeのファイルを Commitして Repositoryに記録する

9.

LAB1 ファイルの変更を記録しよう Windows コマンドプロンプト githandson README.md > mkdir \work\githandson Work Treeを作成 > cd \work\githandson > git init Repositoryを作成 > git config user.name "MATSUOKA Takashi" 操作する人の名前を設定 > git config user.email [email protected] 操作するEメールを設定 > echo hoge > README.md ファイルを作成 > git add -A (←今は気にしないで!) > git commit -m "hoge" Commit Work Tree Commit Repository [main (root-commit) 751c79e] hoge コミットID(の一部)

10.

LAB1 ファイルの変更を記録しよう macOS ターミナル githandson README.md > mkdir -p work/githandson Work Treeを作成 > cd work/githandson > git init Repositoryを作成 > git config user.name "MATSUOKA Takashi" 操作する人の名前を設定 > git config user.email [email protected] 操作するEメールを設定 > echo hoge > README.md ファイルを作成 > git add -A (←今は気にしないで!) > git commit -m "hoge" Commit Work Tree Commit Repository [main (root-commit) 751c79e] hoge コミットID(の一部)

11.

LAB1 Repositoryを覗いてみよう Windows コマンドプロンプト > tree /f .git Repository C:\WORK\GITHANDSON\.GIT │ ... ├─hooks │ ... ├─info │ ... ├─logs │ ... ├─objects │ ... └─refs ...

12.

LAB1 Repositoryを覗いてみよう macOS ターミナル > tree .git Repository .git │ ... ├─hooks │ ... ├─info │ ... ├─logs │ ... ├─objects │ ... └─refs ... (brew install tree)

13.

LAB2 GitオブジェクトとGitリファレンス (Git Object and Git Reference)

14.

LAB2 Repositoryに入っているもの • Git Object Repository データ Blob Object、Tree Object、Commit Object、Tag Object • Git Reference Git Objectへの参照 Tag、Branch • その他

15.

LAB2 Repositoryに入っているもの Windows コマンドプロンプト > tree /f .git Repository C:\WORK\GITHANDSON\.GIT │ ├─objects Git ObjectのID = SHA-1ハッシュ (16進数40桁) │ ├─75 │ │ │ ├─84 │ │ 1c79e0b5e9000abb9d2d8612d22351410fcd6d Git Object 1330c1c88cfa0920385dacb62e290c41bafc29 ... └─refs ├─heads │ ... main Git Reference

16.

LAB2 Repositoryに入っているもの macOS ターミナル > tree .git Repository .git │ ├─objects Git ObjectのID = SHA-1ハッシュ (16進数40桁) │ ├─75 │ │ │ ├─84 │ │ 1c79e0b5e9000abb9d2d8612d22351410fcd6d Git Object 1330c1c88cfa0920385dacb62e290c41bafc29 ... └─refs ├─heads │ ... main Git Reference

17.

LAB2 Git Objectを見てみよう Windows コマンドプロンプト Repository > git cat-file -t 751c79e0b5e9000abb9d2d8612d22351410fcd6d Git Objectの種類を表示 > git cat-file -p 751c79e0b5e9000abb9d2d8612d22351410fcd6d Git Objectの中身を表示 > git cat-file -t 841330c1c88cfa0920385dacb62e290c41bafc29 Git Object Git Reference > git cat-file -p 841330c1c88cfa0920385dacb62e290c41bafc29 > git cat-file -t ebd5eb4fac69d2e2e90296ef1d1da615c4ee5dbc > git cat-file -p ebd5eb4fac69d2e2e90296ef1d1da615c4ee5dbc > type .git\refs\heads\main Git Referenceの中身を表示

18.

LAB2 Git Objectを見てみよう macOS ターミナル Repository > git cat-file -t 751c79e0b5e9000abb9d2d8612d22351410fcd6d Git Objectの種類を表示 > git cat-file -p 751c79e0b5e9000abb9d2d8612d22351410fcd6d Git Objectの中身を表示 > git cat-file -t 841330c1c88cfa0920385dacb62e290c41bafc29 Git Object Git Reference > git cat-file -p 841330c1c88cfa0920385dacb62e290c41bafc29 > git cat-file -t ebd5eb4fac69d2e2e90296ef1d1da615c4ee5dbc > git cat-file -p ebd5eb4fac69d2e2e90296ef1d1da615c4ee5dbc > cat .git/refs/heads/main Git Referenceの中身を表示

19.

LAB2 Work TreeとGit Object、 Git Referenceの関係を図に描いてみよう Work Tree Repository githandson README.md Commit commit 751c79e heads/main

20.

LAB2 Work TreeとGit Object、 Git Referenceの関係を図に描いてみよう Work Tree Repository githandson README.md Commit commit 751c79e heads/main tree 841330c blob ebd5eb4

21.

LAB3 作業ツリーとステージング、コミット (Work Tree and Staging, Commit)

22.

LAB3 Work TreeとStaging、Commit Work Tree ディレクトリ Staging Area ファイル Repository blob commit Staging tree blob Commit index tree > git add -A > git commit -m "hoge" blob

23.

LAB3 ファイルの変更を記録する 現在の Work Treeのファイルを Stagingして Commitして Repositoryに記録する

24.

LAB3 Staging Areaを見てみよう Windows コマンドプロンプト > git ls-files --stage Repository Staging Area

25.

LAB3 Staging Areaを見てみよう macOS ターミナル > git ls-files --stage Repository Staging Area

26.

LAB4 コミット履歴 (Commit History)

27.

LAB4 ファイルの変更を記録する Work Tree githandson Repository README.md Commit commit 751c79e tree 841330c blob ebd5eb4

28.

LAB4 ファイルの変更を複数記録する Repository Work Tree ディレクトリ ファイル commit tree blob commit tree blob commit tree blob 1st Commit 2nd Commit 3rd Commit Commit History

29.

LAB4 ファイルの変更を複数記録しよう Windows コマンドプロンプト Work Tree githandson README.md > echo fuga >> README.md > git add README.md > git commit -m "fuga" 3nd Commit 2nd Commit Repository 2nd Commit > echo piyo >> README.md > git add README.md > git commit -m "piyo" 3rd Commit

30.

LAB4 ファイルの変更を複数記録しよう macOS ターミナル Work Tree githandson README.md > echo fuga >> README.md > git add README.md > git commit -m "fuga" 3nd Commit 2nd Commit Repository 2nd Commit > echo piyo >> README.md > git add README.md > git commit -m "piyo" 3rd Commit

31.

LAB4 Commit Historyを見てみよう Windows コマンドプロンプト Repository Commit History > git log --oneline --all --graph > git cat-file -p <コミットID>

32.

LAB4 Commit Historyを見てみよう macOS ターミナル Repository Commit History > git log --oneline --all --graph > git cat-file -p <コミットID>

33.

LAB5 チェックアウトとHEAD (Checkout and HEAD)

34.

LAB5 過去のCommitに切り替える Repository 1st commit tree blob 2nd commit tree blob 3rd commit tree blob Work Tree ディレクトリ ファイル Staging Area Staging Checkout blob Commit Checkout Commit History

35.

LAB5 HEAD Repository 1st commit tree blob 2nd commit tree blob 3rd commit tree blob Work Tree ディレクトリ ファイル Staging Area Checkout blob Checkout HEAD Commit History

36.

LAB5 HEADを切り替えてみよう Windows コマンドプロンプト Work Tree githandson > git log --oneline --all --graph README.md > git checkout <コミットID> > type .git\HEAD > type README.md Checkout Repository Commit History HEAD

37.

LAB5 HEADを切り替えてみよう macOS ターミナル Work Tree githandson > git log --oneline --all --graph README.md > git checkout <コミットID> > cat .git/HEAD > cat README.md Checkout Repository Commit History HEAD

38.

LAB6 タグ (Tag)

39.

LAB6 Commitに名前を付ける Repository Commit History Commit 1st commit 751c79e 2nd commit 14c7932 3rd commit a93ab15 Checkout tag Annotated Tag Lightweight Tag tags/1.0.0L tags/1.0.0A

40.

LAB6 Tagを作ってみよう Windows コマンドプロンプト > git tag 1.0.0L 14c7932 Repository > type .git\refs\tags\1.0.0L Commit History 1st commit 751c79e tags/1.0.0L > type .git\refs\tags\1.0.0A 2nd commit 14c7932 3rd commit a93ab15 > git tag -a 1.0.0A -m "anno" 14c7932 > git log --oneline --all --graph tags/1.0.0A

41.

LAB6 Tagを作ってみよう macOS ターミナル > git tag 1.0.0L 14c7932 Repository > cat .git/refs/tags/1.0.0L Commit History 1st commit 751c79e tags/1.0.0L > cat .git/refs/tags/1.0.0A 2nd commit 14c7932 3rd commit a93ab15 > git tag -a 1.0.0A -m "anno" 14c7932 > git log --oneline --all --graph tags/1.0.0A

42.

LAB7 ブランチ (Branch)

43.

LAB7 コミットフローに名前を付ける Repository Commit History 1st commit 751c79e 2nd commit 14c7932 3rd commit a93ab15 Tag tags/1.0.0 Branch heads/develop HEAD

44.

LAB7 コミットフローに名前を付ける Repository Commit History 1st commit 751c79e 2nd commit 14c7932 3rd commit a93ab15 New commit xxxxxxx Tag tags/1.0.0 Branch heads/develop HEAD

45.

LAB7 コミットフローに名前を付ける Repository Commit History 1st commit 751c79e 2nd commit 14c7932 3rd commit a93ab15 New commit xxxxxxx Tag tags/1.0.0 Branch heads/develop HEAD

46.

LAB7 CommitしてBranchを観察しよう Windows コマンドプロンプト > git branch develop 14c7932 Repository > git checkout develop Commit History 1st commit 751c79e tags/1.0.0L > type .git\refs\heads\develop > type .git\HEAD 2nd commit 14c7932 3rd commit a93ab15 > type .git\refs\tags\1.0.0L > echo piyo >> README.md heads/develop > git add README.md > git commit -m "hogera" > type .git\refs\tags\1.0.0L > type .git\refs\heads\develop > type .git\HEAD

47.

LAB7 CommitしてBranchを観察しよう macOS ターミナル > git branch develop 14c7932 Repository > git checkout develop Commit History 1st commit 751c79e tags/1.0.0L > cat .git/refs/heads/develop > cat .git/HEAD 2nd commit 14c7932 3rd commit a93ab15 > cat .git/refs/tags/1.0.0L > echo piyo >> README.md heads/develop > git add README.md > git commit -m "hogera" > cat .git/refs/tags/1.0.0L > cat .git/refs/heads/develop > cat .git/HEAD

48.

当イベントは、単にGitの操作を学ぶのではなく、変更履歴やブランチ管理などの Git機能がどのように実装されているのか という仕組みを理解した上で、実際の 操作方法を学ぶハンズオンです。 どのように保存されているのか どのように操作するのか

49.

LAB1~7 全体像 Repository Staging Area Work Tree index Staging Tag blob commit tree blob commit tree blob Commit Checkout Checkout HEAD Branch Commit History … Git Object … Git Reference

50.

LAB8 Visual Studio Code

51.

LAB8 Visual Studio Code https://code.visualstudio.com/docs/sourcecontrol/overview

52.

LAB8 VSCode フォルダーを開く フォルダーを開く

53.

LAB8 VSCode ソース管理 ソース管理 HEAD -> Staging Area Staging Area -> Work Tree Commit Historyの一部

54.

LAB8 VSCode エクスプローラー エクスプローラー Commit Historyの一部

55.

LAB8 Commitしてみよう ソース管理 HEAD -> Staging Area Staging Area -> Work Tree Commit Historyの一部

56.

LAB8 Git Graph Commit History

57.

LAB8 Commit Historyを見てみよう Commit History