- 設定項目やリポジトリの作成
- configの確認
- git config -l
- -listと同義
- git config -l
- ユーザー名とメールアドレス
- git config --global user.name "[name]"
- git config --global user.email "[email address]"
- gitの改行コード自動変換をオフにする
- git config --global core.autoCRLF false
- エイリアスの設定(例)
- git config --global alias.co checkout
- git config --global alias.st status
- git config --global alias.br branch
- git config --global alias.ci commit
- HEADの意味
- HEADは現在の最新状態
- git用のディレクトリの初期化
- git init
- 共有リポジトリ(bareリポジトリ)の作成時
- configの確認
- リポジトリやワーキングツリーの状態確認
- log
- log一行表示
- git log --oneline
- 変更内容確認
- git log -p
- 変更ファイル確認
- git log --stat
- ツリーの分岐を表示
- git log --graph
- log一行表示
- reflog
- 今までのHEADの移動履歴を見る
- git reflog
- 今までのHEADの移動履歴を見る
- status
- 現在の状況を確認
- git status
- 現在の状況を確認(簡易)
- git status -s
- git status --short
- 現在の状況を確認
- diff
- 差分を確認する(作業フォルダ)
- git diff
- 差分を確認する(ステージング)
- git diff --cached
- 差分を確認する(作業フォルダ)
- log
- 変更の保存
- add
- ファイルを指定してステージングに上げる
- git add [file path]
- 全てのファイルをステージングに上げる
- git add .
- ファイルを指定してステージングに上げる
- commit
- ステージングにあるものをリポジトリに反映する
- git commit
- エディタを開かずワンラインでメッセージ付きcommit
- git commit -m "[message]"
- エディタを開かずワンラインでメッセージ付きcommit(全てのファイルのaddも同時に行う)
- git commit -am "[message]"
- git add .
- git commit -m "[message]"
- と同じ意味
- git commit -am "[message]"
- 前回のcommitを修正
- git commit --amend
- ステージングにあるものをリポジトリに反映する
- add
- ワーキングツリーの状態変更や整理
- checkout
- reset
- ステージングをHEADの状態に戻す
- git reset HEAD [file name]
- 作業ディレクトリのファイルには影響しない
- git reset --mixedの省略
- git reset HEAD [file name]
- すべて(作業ディレクトリ・ステージングエリア)を[commit id]の状態に戻す
- git reset --hard [commit id]
- すべて(作業ディレクトリ・ステージングエリア)を[commit id]のひとつ前の状態に戻す
- git reset --hard [commit id]^
- すべて(作業ディレクトリ・ステージングエリア・リポジトリの状態)を[commit id]の状態に戻す
- git reset --hard [commit id]
- [commit id]を取り消してHEADを[commit id]のひとつ前のcommitに戻す
- git reset --soft [commit id]^
- HEADの状態しか変わらない
- git reset --soft [commit id]^
- 直前のHEADに戻る
- git reset --hard ORIG_HEAD
- 間違えてresetした時など、HEADを変更した場合にreset前のHEADの状態に戻れる
- ORIG_HEADにはひとつ前のHEADの位置が記録されている
- git reset --hard ORIG_HEAD
- ステージングをHEADの状態に戻す
- branch
- 現在のbranchの一覧を確認する
- git branch
- branchを作る
- git branch [branch name]
- branchを削除する
- git branch -d [branch name]
- 現在のbranchの一覧を確認する
- merge
- branchをmerge(merge先のbranchにいる状態で)
- git merge [branch name]
- masterにdevelopをmergeするときはmasterにいる状態で
- git merge develop
- masterにdevelopをmergeするときはmasterにいる状態で
- git merge [branch name]
- branchをmerge(ファストフォワードしない)
- http://d.hatena.ne.jp/sinsoku/20111025/1319497900
- git merge --no-ff [branch name]
- branchをmerge(merge先のbranchにいる状態で)
- rebase
- http://liginc.co.jp/web/tool/79390
- http://tkengo.github.io/blog/2013/05/16/git-rebase-reference/
- 別のコミットになる
- rebaseは以前のコミットを取り消して、新しくコミットしなおしている
- リモートリポジトリにコミットしている場合、巻き戻りや衝突の原因になる
- --onto
- $ git rebase --onto どこへ どこから どのブランチを
- brunchの派生元を切り替える
- git rebase [branch name]
- 現在のブランチの参照元を[branch name]のHEADに付け替える
- git rebase [branch name]
- 競合を解決した後に実行して、再度rebaseする
- git rebase --continue
- rebaseを中止する
- git rebase --abort
- エラーを無視してrebaseする
- git rebase --skip(エラーを無視する)
- interactiveモード
- rebase -i [commit]
- pick(コミットを残す)
- reword(コミットを残すが、コミットメッセージを変更)
- edit(コミットを残すが、コミットしたファイルを修正する)
- squash(一個前のコミットと統合してコミットメッセージを変更する)
- fixup(一個前のコミットに統合する。コミットメッセージは統合先のものを使う)
- exec(shellでコマンドを実行する)
- rebase -i [commit]
- revert
- 指定のコミットの変更を差し戻すコミットを作成する
- git revert
- git resetは対象のコミットまで状態を巻き戻してしまうため、リモート上では行えない。こういう場合にrevertで行った変更を全て戻すコミットを作成する
- git revert
- Merge Commitの時
- 指定のコミットの変更を差し戻すコミットを作成する
- tag
- 現在存在するtagの一覧を見る
- git tag
- 直前のcommitにtagをつける
- git tag [tag name]
- 特定のcommitにtagをつける
- git tag [tag name] [commit id]
- tagを削除する
- git tag -d [tag name]
- 現在存在するtagの一覧を見る
- 作成中のワーキングツリーの退避
- stash
- 変更を一時的に退避する
- git stash
- git stash save
- 変更を一時的に退避する際にメッセージをつける
- git stash save "message"
- 現在退避されている一覧を表示
- git stash list
- N番目に退避したファイルの一覧を表示
- git stash show stash@{N}
- N番目に退避したファイルとHEADの差分を表示
- git stash show -p stash@{N}
- 退避した状態を作業ディレクトリに戻し、退避リストから削除する
- 最新を対象にする
- git stash pop
- 指定の番号を対象にする
- git stash pop stash@{N}
- 最新を対象にする
- 退避リストから削除せずに退避した状態を作業ディレクトリに戻す
- 最新を対象にする
- git stash apply
- 指定の番号を対象にする
- git stash apply stash@{N}
- 最新を対象にする
- 退避リストから削除
- unstage ファイルを全てスタッシュ
- git stash -k
- untrackファイルも含めて全てスタッシュ
- git stash -u
- 変更を一時的に退避する
- stash
- ファイルの削除や移動 名前の変更
- rm mv
- git rm [file path]
- git rm --cached [file path]
- バージョン管理からファイルを削除する
- git mv [file path] [renamed file path]
- ファイル名を変更してcommitする
- git rm -r --cached
- ステージングを綺麗にする
- rm mv
- リモートへの同期や反映
- remote
- clone
- 共有リポジトリを複製する
- git clone [remote url]
- git clone [remote url] [local directory]
- 共有リポジトリを複製する
- push
- 共有リポジトリにpush(反映)する
- git push [bookmark name] [branch name]
- remoteの[bookmark name]に[branch name]branchをpushする
- git push [bookmark name] [branch name]
- 共有リポジトリにpush(反映)する
- fetch
- pull
- fetch→mergeを自動で行う
- 共有リポジトリからpull(取得)する
- git pull [bookmark name] [branch name]
- remoteの[bookmark name]から[branch name]branchを取得してmergeする
- git pull [bookmark name] [branch name]
- fetch→rebaseを自動で行う
- git pull --rebase [bookmark name] [branch name]
- remoteの[bookmark name]から[branch name]branchを取得してrebaseする
- git pull --rebase [bookmark name] [branch name]