gitメモ
ディレクトリ初期化(リポリトリ自体を新規で作成する場合)
git init
取得
git clone ssh://{ユーザ名}@{ホスト名}:{ポート番号}/path/to/remote/repogitory my_repogitory
ローカルブランチ確認
git branch
追跡中のリモートブランチ確認
git branch -r
全ブランチ確認
git branch -a
ブランチのリファレンスを確認
git branch -vv
更新取得
git fetch --all
ブランチの選択
git checkout -b local_branch_name target_branch_name
あるブランチから新しいブランチを作る
git branch new_branch_name origin/new_branch_name
※masterをベースにしたければgit checkout masterしてから実行する
プッシュ(リモート送信)テスト(-n)
git push -n origin new_branch_name
ローカルで作成したリポジトリをリモートにプッシュ(リモート送信)する
git push origin new_branch_name
プッシュするローカルターゲットを常に現在選択中のブランチにする
git config --global push.default "current"
git config --global user.name "ユーザ名"
git config --global user.email メールアドレス
ローカルリポジトリとリモートが紐付いていない時
git branch --set-upstream-to=origin/repo_name repo_name
旧
git branch --set-upstream repo_name origin/repo_name
差分表示(すべて)
git diff
差分表示(ファイルごと)
git diff path/to/file
差分表示(ステージに上げたものすべて)
git diff --cached
差分表示(ステージに上げた当該ファイル)
git diff --cached path/to/file
現在のブランチの更新一時退避一覧
git stash list
現在のブランチの内容を一時保存(一つずつ)
git stash save
※saveは省略可
現在のブランチにStashした内容を持ってくる(一つずつ)
git stash pop
現在のブランチにStashした内容を持ってくる(id指定)
git stash pop stash@{0}
指定したStashを削除
git stash drop stash@{0}
コミット対象追加
git add some_file1 some_file2
コミット対象追加(対話モードで選択)
git add -p some_file1 some_file2
コミット
git commit
更新内容を元に戻す
git checkout HEAD some_file
コミット状態を取り消し
git reset --soft HEAD
コミットとaddを取り消し
git reset HEAD
コミット後、そのコミット状態を取りやめる
git reset --hard HEAD
push後にreset --hardかけた場合の強制プッシュ
git push -f
ログを確認
git log
ログを確認(ファイル毎差分表示)
git log -p
ログを確認(更新ファイル表示)
git log --stat
ログを確認(直近3件)
git log -3
※数字のぶんだけさかのぼって表示
コンフリクト時、現在のファイルをそのまま採用する
git checkout --ours file_name
コンフリクト時、マージしてきたファイルをそのまま採用する
git checkout --theirs file_name