LoginSignup
29
28

More than 5 years have passed since last update.

知らなかったGitコマンドまとめ

Posted at

GitHub実践入門 ~Pull Requestによる開発の変革 (WEB+DB PRESS plus)」という本がとても評判良いみたいなので買いました。まだ読んでる途中ですが、評判通りの本です。

知らなかったgitコマンドもいくつかあったのでメモしておきます。

log系

コミットメッセージの1行目のみを表示する

git log --pretty=short

ファイルの差分も一緒に表示する

git log -p

ブランチを視覚的に確認する

$ git log --graph


* commit c1a9b606b28bc3e163925b60f0f7f1b4676f0726
| Author: koogawa <koogawa.app@hoge.com>
| Date:   Sun Mar 16 01:21:15 2014 +0900
|
|     Add image files.
|
*   commit fe8f161580326f764ebecf3d63e1ea24850d662d
|\  Merge: 9ed9d13 0260e16
| | Author: koogawa <koogawa.app@hoge.com>
| | Date:   Sun Mar 16 01:16:29 2014 +0900
| |
| |     Merge branch 'line'
| |
| * commit 0260e16d215835f0e32191e2b1af21f7057d9576
| | Author: koogawa <koogawa.app@hogel.com>
| | Date:   Sat Mar 15 13:56:53 2014 +0900
| |
| |     update ignore
| |
| * commit bebb60ed276de1e75afe6ddb3728d42a0f2aba1c
| | Author: koogawa <koogawa.app@hoge.com>
| | Date:   Sat Mar 15 10:27:43 2014 +0900

| |
| |     Add send to LINE feature
| |
* | commit 9ed9d13715811c14557131e4917ee2352714da29
|/  Author: koogawa <koogawa.app@gmail.com>
|   Date:   Sat Mar 15 11:51:51 2014 +0900
|

これは面白い!

ブランチ系

一つ前のブランチに切り替える

$ git checkout -

$ cd - みたいな感じで切り替えられるらしい。

コミット系

直前のコミットメッセージを修正する

git commit --amend

git add と git commit を同時に

git commit -am "Add files"

Issue系

関連するIssueにコミットを表示する

コミットする際、

git commit -m "Add feature #24"

のように Issue 番号を含めると、対象の Issue にこのコミット情報が表示される。

IssueをCloseする

コミットする際、

git commit -m "close #24"

のように記述すれば、該当する Issue が Close される。close の他、

  • fix
  • fixes
  • fixed
  • close
  • closes
  • closed
  • resolve
  • resolves
  • resolved

でもいける。

29
28
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
29
28