gitのメモ
基本操作
- ワークディレクトリに変更がないか確認
- git status
- コミット対象ファイルをインデクスに追加
- git add ファイル名
- カレントディレクトリ以下の全コミット対象ファイルをインデクスに追加
- git add .
- git addしたものを消す
- git rm --cached ファイル名
- git addしたものを複数消す(カレントディレクトリ以下)
- git init後の最初のaddで全ファイル登録した際に、いらないgitingoreに書き忘れたファイルがあるときに、一気にaddしなかったことにできるので便利
- git rm --cached -r .
- コミット
- git commit -m "コミットメッセージ"
- ログ一覧表示(差分コード含め最新2件のみ表示)
- git log -p -2
- ブランチ間の差分
- git diff ブランチA ブランチB
ブランチ関係
- ブランチを表示
- git branch -a
- ブランチ作成
- git branch hogehoge
- ブランチ移動
- git checkout hogehoge
- git checkout origin/remotehoge
- リモートのブランチ(origin/remotehoge)をローカルブランチ(hogehoge2)に作成して移動
- git checkout -b hogehoge2 origin/remotehoge
- ローカルブランチをリモートに作成/反映(remotes/origin/hogehogeが作成される)
- git push origin hogehoge
- hogehogeローカルブランチの内容をremotes/origin/remotehogehogeに作成/反映
- git push origin hogehoge:remotehogehoge
- ブランチを削除
- git branch -d hogehoge
- リモートブランチを削除
- git branch -r -d origin/remotehogehoge
- git push origin :remotehogehoge
- リモートブランチのリネーム(別リモートブランチ(remotehoge2)にコピーしてremotehogeを削除)
- git checkout -b localhoge origin/remotehoge
- git push origin localhoge:remotehoge2
- git push origin :remotehoge
- 全ローカルブランチをリモートにPush
- git push --all
マージ
- masterにブランチ(hogehoge)をマージ
- git checkout master
- git merge hogehoge