$ cd ichiyasa //ディレクトリに移動
$git init //ローカルリポジトリ作成
Macの場合、コマンドの実行結果にhintが表示されることがありますが、特に操作は必要ありません。
標準のブランチ名をgit configコマンドを使って変更できると記載されています。
$ ls -a
. .. .git Git_MEMO.md
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Git_MEMO.md
nothing added to commit but untracked files present (use "git add" to track)
『Untracked files』に表示されているファイルはGitの管理下に入っていないことを指します。
ステージングエリアに登録
git add Git_MEMO.md
ファイル指定の書き方ですが下記のように指定できます。
$ git add . //カレントディレクトリ配下全て
$ git add subDirectory //subDirectoryのディレクトリ全て
$ git add subDirectory/file.md //subDirectoryのfile.mdのみ
ステージングエリアに登録されたことを確認
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: Git_MEMO.md
実行結果が『Untracked files』から『Changes to be committed:』に変更されました。
ファイルの差分を確認
git diff
diff --git a/Git_MEMO.md b/Git_MEMO.md
index 54f4fe1..0fdf6f4 100644
--- a/Git_MEMO.md
+++ b/Git_MEMO.md
@@ -1,2 +1,5 @@
-#Git 学習メモ
-## Gitコマンド
\ No newline at end of file
+# Git 学習メモ
+
+
+- ローカルリポジトリを作成する
+ - git init
\ No newline at end of file
実行結果の先頭に『+』がついていれば追加、『-』がついていれば削除
ステージングエリアとGitディレクトリ(前回のコミット)の差分を表示するオプション --cached
$ git diff --cached
ファイルをコミットする
$ git commit
hint: Waiting for your editor to close the file...
1.自動的にVS codeが立ち上がる
行頭に#がついているのはコメントでコミットメッセージには含まれない。
2.コミットメッセージを書く
- 1行目にコミットタイトルを書く(Gitの学習メモを作成)
- 2行目は空白
- 3行目から詳細を書く
この書き方がGitの公式サイトに書かれているおすすめの書き方です。
Git - git-commit Documentation
3.保存してVS codeを閉じる
[master (root-commit) 175f135] Gitの学習メモ
1 file changed, 2 insertions(+)
create mode 100644 Git_MEMO.md
ターミナルに上記の実行結果が出る
$ git status
On branch master
nothing to commit, working tree clean
コミットメッセージ1行の時は素早くコミット -m
$ git commit -m "ローカルリポジトリの作成"
[master 4f15281] ローカルリポジトリの作成
1 file changed, 5 insertions(+), 2 deletions(-)