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

9.3K 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ハンズオン 2025/ 7/3 仕組みから学ぶGitハンズオン 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 ファイルの変更を記録しよう 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 Repositoryを覗いてみよう > tree /f .git Repository C:\WORK\GITHANDSON\.GIT │ ... ├─hooks │ ... ├─info │ ... ├─logs │ ... ├─objects │ ... └─refs ...

11.

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

12.

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

13.

LAB2 Repositoryに入っているもの > 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

14.

LAB2 Git Objectを見てみよう 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の中身を表示

15.

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

16.

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

17.

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

18.

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

19.

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

20.

LAB3 Staging Areaを見てみよう > git ls-files --stage Repository Staging Area

21.

LAB4 コミット履歴 (Commit History)

22.

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

23.

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

24.

LAB4 ファイルの変更を複数記録しよう 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

25.

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

26.

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

27.

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

28.

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

29.

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

30.

LAB6 タグ (Tag)

31.

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

32.

LAB6 Tagを作ってみよう > 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

33.

LAB7 ブランチ (Branch)

34.

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

35.

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

36.

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

37.

LAB7 CommitしてBranchを観察しよう > 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

38.

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

39.

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

40.

LAB8 Visual Studio Code

41.

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

42.

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

43.

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

44.

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

45.

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

46.

LAB8 Git Graph Commit History

47.

LAB8 Commit Historyを見てみよう Commit History