git関連でよく使うコマンドメモ
参照系
ローカルブランチと、今いるブランチを確認する git branch
すべてのローカルブランチ一覧 git branch -a
更新があるか確認 git status
addの予行演習 git add --dry-run .
カレントブランチのファイル一覧表示 git ls-files
ブランチ同士の差分確認 git dff git diff --name-only cranch1 branch2
コミット履歴閲覧 git log git log -n 100
ブランチ系
ローカルブランチと、今いるブランチを確認する git branch
ブランチ作成 git branch <ブランチ名>
作業ブランチ変更 git checkout <ブランチ名>
更新関連のコマンド
ステージにファイルを追加 git add . :すべての変更ファイル git add -A:〃 git add [file name]:指定したファイルのみ追加
ステージから削除 git reset:全ファイル git reset [file name]:指定ファイル
ステージのファイルをローカルリポジトリにコミット git commit -m "コメント" :コメントしてコミット git commit :メッセージを入力して完了 or メッセージなしで中止
コミットメッセージを修正 git commit --amend -m:コミットメッセージを修正 git commit --amend :メッセージを入力して完了 or メッセージなしで中止
コミット取り消し ※まず「git log」でIDを調べる。(直前のやつはHEAD指定) git reset --soft [ID] :コミットのみ取り消し git reset --mixed [ID]:コミットとステージから取り消し git reset [ID] :〃 git reset --hard [ID] :コミットとステージとワークツリーも修正
プッシュ git push git push origin branch
プル git pull git pull origin branch
よくやる決まった流れ①:clone(pull)~プルリクエスト作成
クローン or pull git clone https://github.com/???????.git ディレクトリ git clone https://[git token]@github.com/???????.git ディレクトリ git pull git pull origin branch
ブランチの作成/移動 git branch branch_name git checkout branch_name
~~~~~(作業)~~~~~
コミット、プッシュ git status git diff →新規ファイルは出ないので注意 git add file_name git diff git commit -m "comment" git push origin branch_name
[画面に移動] 画面に出てきたら、「compare pull reqest~」みたいなところおす 必要なところ記入してレビュワー設定 create pull requestおす
よくやる決まった流れ②:ローカルブランチ最新化
現在のブランチ確認 git branch
main(取り込みたい)ブランチに移動 git checkout branch_name
リモートの変更を取得 git pull origin main
作業ブランチに戻る git checkout branch_name
取り込んだ変更マージ git merge origin branch_name