Share
Embed
Transcript
40 slides
-
3 40 とりあえず覚えたいコマンド git init git add git commit git
status git diff git log git clone git remote git fetch git switch git merge git rebase ローカルリポジトリの操作 ブランチの操作 状態や歴史の確認 リモートとのやりとり 「とりあえず」でも こんなにある -
4 40 git log のオプション(抜粋) --abbrev-commit --abbrev[=<n>] --after=<date> --all --all-match
--alternate-refs --ancestry-path --anchored=<text> --author-date-order --author=<pattern> --basic-regexp --before=<date> --binary --bisect --boundary --branches[=<pattern>] --break-rewrites[=[<n>][/<m>]] --cc --check --cherry --cherry-mark --cherry-pick --children --color-moved-ws=<modes> --color-moved[=<mode>] --color-words[=<regex>] --color[=<when>] --combined-all-paths --committer=<pattern> --compact-summary --cumulative --date-order --date=<format> --decorate-refs- exclude=<pattern> --decorate-refs=<pattern> --decorate[=short|full|auto|no] --dense --dense --diff-merges=[options] --dirstat-by-file[=<param1,param2>…] --dirstat[=<param1,param2,…>] --do-walk --dst-prefix=<prefix> --encoding=<encoding> --exclude=<glob-pattern> --expand-tabs=<n> --ext-diff --extended-regexp --find-copies-harder --find-copies[=<n>] --find-object=<object-id> --find-renames[=<n>] --first-parent --fixed-strings --follow --format=<format> --full-diff --full-history --full-index --function-context --glob=<glob-pattern> --graph --grep-reflog=<pattern> --grep=<pattern> --histogram --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol --ignore-matching-lines=<regex> --ignore-missing --ignore-space-at-eol --ignore-space-change --ignore-submodules[=<when>] --indent-heuristic --inter-hunk-context=<lines> --invert-grep --irreversible-delete --ita-invisible-in-index --left-only --left-right --line-prefix=<prefix> --log-size --max-count=<number> --max-parents=<number> --merge --merges --min-parents=<number> --minimal --name-only --name-status --not --notes[=<ref>] --numstat --oneline --output-indicator-context=<char> --output-indicator-new=<char> --output-indicator-old=<char> --output=<file> --parents --patch --patch-with-raw --patch-with-stat --patience --perl-regexp --pickaxe-all --pickaxe-regex --pretty[=<format>] --raw --reflog --regexp-ignore-case --relative-date --relative[=<path>] --remotes[=<pattern>] --remove-empty --reverse --right-only --rotate-to=<file> --shortstat --show-linear-break[=<barrier>] --show-notes[=<ref>] --show-pulls --show-pulls --show-signature --simplify-by-decoration --simplify-merges --since=<date> --single-worktree --skip-to=<file> --skip=<number> --source --sparse --src-prefix=<prefix> --stat[=<width>[,<name-width>[,<count>]]] --stdin --submodule[=<format>] --summary --tags[=<pattern>] --text --textconv --topo-order --unified=<n> --until=<date> --walk-reflogs --word-diff-regex=<regex> --word-diff[=<mode>] --ws-error-highlight=<kind> -
11 40 リポジトリの種類 ローカルリポジトリ (local repository) 手元のPCにあるリポジトリのこと ワーキングツリーを持つ リモートリポジトリ (remote
repository) リモート(ネットワークの向こう側)にある ワーキングツリーを持たない ベアリポジトリ (bare repository) ワーキングツリーを持たないリポジトリ 一般にリモートはベアリポジトリ -
13 40 コミット Gitでは「歴史」を丸と線で表現する • 丸:ある時点の「状態」 • 線:二つの状態の関係(差分) 三日前 二日前
昨日 歴史 昨日から修正を加えたプロジェクト (スナップショット) -
14 40 コミット コミット:現在の状態を保存して「歴史」に加える 三日前 二日前 昨日 コミット 歴史 (スナップショット)
昨日から修正を加えたプロジェクト (スナップショット) -
15 40 コミット 三日前 二日前 昨日 歴史 今日 この玉それぞれを「コミット」と呼ぶ この玉を新たに作る作業を「コミットする」と呼ぶ
commit (名詞) : Gitの歴史のある「点」(スナップショット) commit (動詞): Gitの歴史に新たにスナップショットを付け加えること https://git-scm.com/docs/gitglossary A Git Glossary -
16 40 コミット 歴史上の任意の地点に戻ることができる 今日の状態 二日前の状態 今日 昨日 二日前 三日前
今日 昨日 二日前 三日前 ワーキングツリー コミットはセーブファイルのようなもの -
18 40 インデックスとステージング Gitには三種類の場所がある ワーキングツリー(workingtree) 現在修正中のプロジェクトファイルがある場所 インデックス (index) ステージングをする場所 コミットするスナップショットを用意する
リポジトリ (repository) 歴史(コミット)を保存する場所 -
19 40 インデックスとステージング 本番環境に反映させる前に準備をする場所 ローカルPCで修正 ステージング環境 本番環境 ローカルPC ここで動作テスト 本番環境へ反映
ステージング環境 ステージング環境に修正を反映すること ステージング -
21 40 インデックスとステージング ワーキングツリー インデックス リポジトリ file1 file2 ステージング file1
file2 ワーキングツリーの状態(スナップショット)をインデックスに登録 -
22 40 インデックスとステージング ワーキングツリー インデックス リポジトリ file1 file2 コミット file1
file2 インデックスにステージングされた状態をリポジトリに登録 file1 file2 -
26 40 インデックスとステージング file1 file2 file1 file2 コミットする ワーキングツリー インデックス
リポジトリ file1 file2 -
28 40 インデックスとステージング file1 file2 file1 file2 file1 file2 こんな歴史ができあがった
file1とfile2を追加 file1を修正 file2を修正 Gitでは積極的に歴史を作成、改変する -
30 40 ブランチ 初期化直後 最初のコミット main main 次のコミット main さらに次のコミット
main ブランチ (branch) コミットにつくラベルのようなもの デフォルトでmainというブランチが用意される 自由に作ることができる コミットされると一緒に動く -
31 40 ブランチ main branch ブランチ作成直後 main branch HEAD ブランチの切り替え
main branch HEAD コミット HEAD カレントブランチ (current branch) 「今見ているブランチ」のこと HEADというラベルが指す コミットにより動くのはカレントブランチのみ -
32 40 ブランチ main branch branchを 見ている状態 HEAD main branch
mainに 切り替える HEAD main branch コミットする HEAD ブランチを切り替えながらコミットをすると 一般に歴史が分岐する -
33 40 Detached HEAD状態 main HEAD 通常の状態 main HEAD detached
HEAD状態 HEADがブランチを経由して コミットを指している HEADがブランチから外れ コミットを直接指している 通常、HEADはブランチを指しているが、HEADが直接 コミットを指す状態を頭が取れた(detached HEAD)状態 と呼ぶ -
35 40 マージ main branch mainの スナップショット branchの スナップショット main
branch ファイル追加 mainからbranchへ更新する ための「差分」 玉:スナップショット 線:スナップショット間の差分 -
36 40 マージ main = + コミット (スナップショット) 修正(パッチ) branch
ファイル追加 次のコミット (スナップショット) main branch スナップショット(玉)に、パッチ(線)を適用すると、次のスナップショット(玉)になる -
37 40 Fast-forwardマージ main branch main branch 修正を取り込みたいブランチが、もう一方のブ ランチの直接の祖先である場合、ブランチを移 動するだけでマージが完了する
これをFast-forwardマージ(早送りマージ)と呼ぶ -
38 40 Non-fast forwardマージ main branch main branch 歴史が分岐している場合、マージにより歴史が 合流する
HEAD HEAD 新たに作られるコミットをマージコミット(merge commit)と呼ぶ -
39 40 Non-fast forwardマージ main branch main branch Fast Forwardマージできる場合でもマージコミットを作ることができる
Fast forwardマージすると、マージ元がどこで分岐したかの情報が失われる main branch main branch