Gitのお勉強 1日目
Udemyで以下のコースを受けてみた。
もう怖くないGit!チーム開発で必要なGitを完全マスター
自分の場合、ネットで調べると情報の整理がうまくできないことが多いので、こういう風に体系的に教えてもらった方がありがたい。
ローカルリポジトリでのCommitまでの基本コマンドをメモ書きがてら書いておく。
ワークツリーでのファイル作成
# 初期化 # .gitディレクトリが作成される # ファイル一覧:圧縮(コード等)、ツリー、コミット、インデックス、設定 $ git init Initialized empty Git repository in C:/Users/rai-j/python_bin/atcoder_trials/.git/ # .git内はこんな感じ $ ls .git/ COMMIT_EDITMSG description hooks/ info/ objects/ config HEAD index logs/ refs/ # ハッシュ化 $ git hash-object R081C_make_a_retangle.py ad6c5ab1513c2f4b58f05b956adea87392cbe88f # addコマンドでステージに圧縮済みファイルを追加 $ git add R081C_make_a_retangle.py warning: CRLF will be replaced by LF in R081C_make_a_retangle.py. The file will have its original line endings in your working directory.
ローカルリポジトリへコミット
# -mはメッセージのオプション # # メッセージの書き方 # 1行目:変更内容の要約 # 2行目:空行 # 3行目:変更した理由 # ステージからリポジトリへコミット $ git commit -m 'add answer R081C' [master (root-commit) 305cb88] add answer R081C 1 file changed, 27 insertions(+) create mode 100644 R081C_make_a_retangle.py
コミット状況の確認
$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) C++/ R080C_adjacent.py R081D_coloring_dominoes.py R081E_dont_be_a_subsequence.py R082C_together.py nothing added to commit but untracked files present (use "git add" to track)
コミット後のデータ確認方法
$ git cat-file -p master^{tree} 100644 blob ad6c5ab1513c2f4b58f05b956adea87392cbe88f R081C_make_a_retangle.py 040000 tree fea172f4f6ef0a096ae5766b02d54459a72d82a6 subdir # コミットをたどるには、parent(以下だと、305cb88...)を追っていけばよい $ git cat-file -p HEAD tree 1a7da0f8af907e650847b7fecc312105113c4118 parent 305cb88f2cd7184e21b2c6eacf189099fdaa8b56 author yasuhitotanaka <sitofourth02@gmail.com> 1506399493 +0900 committer yasuhitotanaka <sitofourth02@gmail.com> 1506399493 +0900 # Treeオブジェクトの先頭の文字列(1a7da)で検索した中身を表示 $ git cat-file -p 1a7da 100644 blob ad6c5ab1513c2f4b58f05b956adea87392cbe88f R081C_make_a_retangle.py 040000 tree fea172f4f6ef0a096ae5766b02d54459a72d82a6 subdir