LoginSignup
2
2

More than 1 year has passed since last update.

gitでよく使うコマンド (gitl, gitd, gits)

Last updated at Posted at 2020-05-01

私がよく使っているコマンドを紹介しておきます。 gitl, gitd, gits というコマンドですが、そういうコマンドが一般に存在するわけではなくて、自分でそういう名前のスクリプトを作ってあるだけです。

gitl

gitのコミットログをCUIで確認するとき、みなさんはどうしてますでしょうか。私は以下のコマンドです。

$ git log --graph --date-order --branches --tags --remotes HEAD --pretty=format:"%Cgreen%ai %Cblue%an %Cgreen%h %Cblue%d %Creset%s"

以下のような感じで、コミットの概要とマージやブランチの状況がわかります。

image.png

オプションが長すぎて覚えられないので、これを打つことはなくてスクリプトにしています。以下のようなスクリプトで gitl という名前と実行権限を付けて、PATHの通った場所に置いています。特定のブランチだけを見ることもできます。

#!/bin/sh

if [ $# -gt 0 ]; then
    git log --graph --date-order \
        --pretty=format:"%Cgreen%ai %Cblue%an %Cgreen%h %Cblue%d %Creset%s" "$@"
else
    git log --graph --date-order --branches --tags --remotes HEAD \
        --pretty=format:"%Cgreen%ai %Cblue%an %Cgreen%h %Cblue%d %Creset%s"
fi

$ gitl
$ gitl devel

このコマンドを私はもう7年以上使っています。

gitd

特定のファイルがいままでどう編集されてきたかのログを見るには、私は以下を使っています。

$ git log --graph --date-order --pretty=format:"%Cblue%d %Cgreen%ai %Cblue%ae %Cgreen%h %Creset%s" -b -p libexec/rbenv

こんなふうに表示されます。コミットごとの差分がログの形式で確認できます。

image.png

gitd という名前でスクリプトにするならこんなファイル。

#!/bin/sh

git log --graph --date-order --pretty=format:"%Cblue%d %Cgreen%ai %Cblue%ae %Cgreen%h %Creset%s" -b -p "$@"

$ gitd libexec/rbenv

このコマンドを私はもう7年以上使っています。

gits

なんのファイルを編集したかわからなくなったときはこれ。

$ git status -s

git status-s を付けずに使うことは私はないです。 git status -sgits という4文字だけで実行できるようにしています。スクリプトにするほどでもなく、aliasで設定できます。

このコマンドを私はもう7年以上使っています。

ほかにも gita とか gitb とかありますけど、省略します 😅

以上。

2
2
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
2
2