2
1

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初期設定(ssh key作成、色付け、エディタ変更、git logを見やすく)

Last updated at Posted at 2018-10-31

gitインストールしたら設定していること。
参考になれば幸いです。

ssh key作成

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

作成した公開鍵(id_rsa.pub)は、githubなどに登録します。
公開鍵の中身は、cat ~/.ssh/id_rsa.pubなどで確認しましょう。
Macなら、cat ~/.ssh/id_rsa.pub | pbcopyで公開鍵の中身をクリップボードにコピーできます。

ユーザー設定

$ git config --global user.name "First-name Family-name"
$ git config --global user.email "your_email@example.com"

自動色付け

$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto

diff,status,branchコマンドに設定。

エディタ変更(vim)

$ git config --global core.editor 'vim -c "set fenc=utf-8"'

UTF-8問題解決設定(※macOS Sierra以前の場合に実施する)

$ git config --global core.precomposeunicode true
$ git config --global core.quotepath false

git logを見やすくする

$ git config --global alias.plog 'log -15 --pretty="format:%C(yellow)%h %C(green)%cd %C(reset)%s %C(cyan)[%an]" --date="format:%Y-%m-%d %H:%M:%S" --no-merges'

コマンドオプションの説明

  • -15 : 最新から15こまでの変更履歴を表示
  • --pretty="format: : logのフォーマット指定
  • %C : 色指定(Color)
  • %h : コミットの短縮版ハッシュ(Hash)
  • %cd : コミットした日付(Committer Date)
  • %s : コミットメッセージの1行目(Subject)
  • %an : 修正者名(Author Name)
  • --date="format: dateのフォーマット
  • %Y : 年
  • %m : 月
  • %d : 日
  • %H : 時
  • %M : 分
  • %S : 秒
  • --no-merges : マージ履歴非表示

確認

git plogを実行すると以下のような形式で出力されるようになります。

$ git plog
4cb474a 2018-10-31 13:59:17 Add hogehoge.yml   [Zama Kei]

~/.gitconfigの確認

設定後の~/.gitconfigは、こんな感じになっています。

$ cat ~/.gitconfig

[user]
	name = First-name Family-name
	email = your_email@example.com
[color]
	diff = auto
	status = auto
	branch = auto
[core]
	editor = vim -c \"set fenc=utf-8\"
[alias]
	plog = log -15 --pretty=\"format:%C(yellow)%h %C(green)%cd %C(reset)%s %C(cyan)[%an]\" --date=\"format:%Y-%m-%d %H:%M:%S\" --no-merges

修正するときは、コマンドを流し直すか、~/.gitconfigを直接編集してもOK。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?