Gitについて、事前に知っておくべきこと
- 現在のプロジェクトファイルがある「Working Directory」。
- Commitした、ソースコードを保存する「Repository」。
- 「Working Directory」と「Repository」間のバッファarea「Staging Area」。
- 「HEAD」は現在のブランチの最新のコミットを意味する。
- 既定のリモートリポジトリは、「origin」。
基本的なコマンド
git --version //現在のgitのバージョンを確認
git clone {url} //リモートリポジトリからクローンする
git status //Localの変更を確認
Log
git log //Commit Logを参照
git log --oneline //Commit LogのCommit IDを表示
git log --decorate //Commit LogのHEADを明示
git log --graph //Commit Logを縦グラフで表示
Checkout
git checkout [branch] //ブランチを変更
git checkout -b [branch] //ブランチを作成&変更
git checkout -b [branch_B] [branch_A] //branch_Aから、branch_Bを作成&変更
Add
git add //ファイルをadd
git add [file]//ファイルをadd
git commit -m “[comment]” //Commit messageを同時に指定
Commit
git commit //ファイルをCommit
git commit -m “[comment]” //Commit messageを同時に指定
Push
git push //Repositoryで変更を反映
git push [repository] [branch] //リモートリポジトリに変更を反映
Fetch
git fetch //Remote Repositoryの最新データを取ってくる
Pull
git pull //Remote Repositoryの変更インポートしてリモートブランチを更新
Reset
git reset --soft HEAD^ //commitをcancelして、ファイルは「staged status」で、Working Directoryに保存
$ git reset --mixed HEAD^ //commitをcancelして、ファイルは「unstaged status」で、Working Directoryに保存
$ git reset HEAD^ //commitをcancelして、ファイルは「unstaged status」で、Working Directoryに保存
$ git reset HEAD~2 //最後の二つのcommitをcancel
$ git reset --hard HEAD^ //commitをcancelして、ファイルは「unstaged status」で、Working Directoryから削除
Revert
git revert [commit id] //commit idのcommitをcancel
Rebase
git rebase [branch] //branchにrebaseする
git rebase --abort //直前のgit rebaseの編集を中止
git rebase --continue //rebaseを続ける
Merge
$ git merge [branch] //現在のbranchを指定したbranchとMerge