LoginSignup
14
14

More than 5 years have passed since last update.

最低限必要だけど、忘れがちなgitコマンド まとめ 備忘録

Posted at

addとかpushはわかるけど、ちょっと忘れがちな基本コマンドたちをまとめました。

作業やり直し関係

$ git commit --amend
     pushしてない直前のコミットを、このコミットに置き換える

e.g)
$ git commit -m 'aaaa'
$ git add huge
$ git commit --amend
最後のコミットがその前のコミットを上書きします。

$ git status
     ワーキングコピーでの状況の確認
     ここの表示に「こんな時はこんなコマンドを打ってね」って出ます(・∀・)!

e.g)
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

   modified:   hogehoge.pm
$ git reset HEAD hoge.pm
     ステージから下げる
     (addしてしまったものをaddしてない状態にする)
$ git checkout -- hoge.pm
     ワーキングディレクトリでの変更をもとに戻す

コミット履歴関係

$ git log -p -2
-p
     書くコミットのdiffを見れる
-2
     直近の2エントリに指定
$ git log --stat
--stat
     各コミットエントリに続けて、変更されたファイルの一覧・ファイル数、追加削除された行数が表示される
--shortstat
     --statのうち、変更/追加/削除の業のみ表示
--name-only

e.g)
commit a1tekitof0sohochazuke75hogeabomberyeah9e6
Author: Ochazuke Fire
Date: Mer Jue 15 11:00:00 2013 -0700

first commit

template/hogehoge | 6 ++++++
Rakefile | 23 +++++++++++++++++++++++
lib/hoge/O/hoge/fire.pm | 25 +++++++++++++++++++++++++
3 files changed, 54 insertions(+), 0 deletions(-)

$git log --pretty=oneline
--pretty
     ログ出力形式を設定出来る
=oneline
     各コミットを1行で表示

e.g)
ca82a6ochazukedaisuki2690a93763949 changed the version number
085bb cb608e1e845sonnnanisukijanie7 removed unnecessary test code
a1tekisutowireioiaouhgoasga0de2209e6 first commit

$ git log --pretty=format:"%h - %an, %ar : %s"
--format
     独自のログ出力フォーマットを指定
$ git log --pretty=format:"%h %s" --graph --since=2.week
--graph --author=hoge
     グラフの表示
--since, --until, -before, -after
     ログ出力対象期間を設定
     = “2008-01-15”
          絶対日時指定
     =2 years 1 day 3 minutes ago
          相対日時指定
14
14
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
14
14