目次
- 1 git init
- 2 git add [file name] または git add .
- 3 git commit -m “[message]”
- 4 git checkout [file name] または git checkout .
- 5 git reset HEAD^ —hard
- 6 Git で管理しないファイル
- 7 git branch [branch name]
- 8 git checkout [branch name]
- 9 git checkout -b [branch name]
- 10 git checkout [base commit ID] -b [branch name]
- 11 git merge [branch name] —no-edit
- 12 git log —all —graph
- 13 git branch -d [branch name]
- 14 git branch -m main master
- 15 コンフリクト
git init
- 新しいプロジェクトで使用します
git add [file name] または git add .
- ステージングします
- 変更を加えたリポジトリからコミットしたいファイルを指定します
- shift + cmd + p ⇒ copy relative path で現在開いているファイルのパスを取得できます
git commit -m “[message]”
- コミットします
- ステージングからリポジトリに変更履歴を登録します
git checkout [file name] または git checkout .
- ステージング、コミット前の変更をすべて破棄します
git reset HEAD^ —hard
- コミット後に1つ前のコミットへ戻します
- ^の数で何個前のコミットへ戻るか指定します
- git log でid を確認して指定することもできます
Git で管理しないファイル
- .gitignore に指定
- パスは.gitignore からの相対パス
git branch [branch name]
- 指定した名前のブランチを作成します
- git branch でブランチの一覧を確認できます
git checkout [branch name]
- 指定したブランチに切り替えます
- git branch で現在のブランチに*がついているのが、確認できます
git checkout -b [branch name]
- ブランチを作って切り替えます
git checkout [base commit ID] -b [branch name]
- 指定したコミットIDからブランチを作成します
- コミットID はgit log で確認できます
git merge [branch name] —no-edit
- ブランチをマージします
- main にマージするときは git checkout main 後に実行します
git log —all —graph
- ブランチの状態を含めてコミットを一覧表示します

- VSCode のソース管理と同じ表示です

git branch -d [branch name]
- マージ後に不要なブランチを削除します
- 間違ってブランチを切ったときに消したい場合、git branch -D [branch name]で強制削除する
- -D 大文字は強制削除
git branch -m main master
- ブランチの名称を変更します
コンフリクト
- merge が失敗します
- git status で unmerged の表示を確認できます
- unmerged のファイルを確認し、<<
- コンフリクト解消後は git commit -a —no-edit によりマージコミットされます