12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Git コマンド簡単リファレンス

Last updated at Posted at 2015-07-27

初期設定する

$ git config --global user.name "<your name>"
$ git config --global user.email "<your email>"
$ git config --global color.ui true # カラー出力する
$ git config -l # 設定値を表示する

初期化する

$ git init # リポジトリを作る

ログを見る

$ git log --oneline # ログの一列表示
$ git log -p # 変更内容を見る
$ git log --stat # ファイルごとの変更箇所を見る

現在の状況を把握する

$ git status # 現在の状況を把握する
$ git checkout -- <file> # 変更を取り消す

差分を確認する

$ git diff # ステージング前の差分を確認する
$ git diff --cached # ステージング後の差分を確認する

ステージングする

$ git add . # 現在のディレクトリ配下のファイルをすべてステージングする
$ git rm / git mv # ステージングしたファイルを削除/移動する

コミットする

$ git commit -m "comment" # 1行程度のコメント付きでコミットする
$ git commit -am "comment" # ステージングして、コミットする
$ git commit --amend # 直前のコミットを修正する

過去のコミットした状態に戻る

$ git reset --hard HEAD # 直前のコミットに戻す
$ git reset --hard <commit id> # 任意のコミットに戻す。<id>は'git log'で確認する

ブランチを作る

$ git branch # ブランチの状態を見る
$ git branch <branch name> # ブランチを作る
$ git checkout <branch name> # ブランチを移動する
$ git checkout -b <branch name> # ブランチを作って移動する
$ git branch master # masterブランチに戻る
$ git merge <branch name> # masterブランチにマージする
$ git branch -d <branch name> # ブランチを削除する

リモートリポジトリを使う

$ git remote add origin <repos location> # リモートリポジトリを登録する
$ git config -l # リポジトリの一覧を表示する
$ git remote rm origin # リポジトリの登録を削除する

リポジトリの内容を共有する

$ git clone <repos location> <dir name> # 指定したディレクトリに複製する
$ git push origin master # リモートリポジトリにプッシュする
$ git pull origin master # リモートリポジトリからプルする

タグをつける

$ git tag <tag name> # 直前のコミットにタグをつける
$ git tag # タグを一覧で表示する
$ git tag <tag name> <commit id> # 任意のコミットにタグをつける
$ git tag -d <tag name> # タグを削除する

エイリアスをつける

$ git config --global alias.co checkout
$ git config --global alias.st status
$ git config --global alias.br branch
$ git config --global alias.ci commit

コメントを英語で書く

  • 現在形で書く
  • 主語は不要
  • ネタ帳
  • Fix foobar(~を修正した場合)
  • Modify foobar(~を変更した場合)
  • Improve foobar(~を改良した場合)
  • Revert foobar(~の変更を取り消した場合)
  • Add foobar(~を追加した場合)
  • Change A to B(AからBに変更した場合)
  • Finish foobar(~の開発を終了した場合)
12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?