LoginSignup
21
21

More than 5 years have passed since last update.

開発環境作ったらとりあえずGitの設定する (git graph + 改行タブ自動変換)

Posted at

私は何かの開発環境を作ったら、とりあえずGitの設定をします。

どんな設定をしているかをお恥ずかしいながら晒してみます。

/etc/gitconfig
[color]
    diff = true
    branch = true

[receive]
    denyCurrentBranch = refuse
    denyNonFastForwards = true
    denyDeletes = true

[alias]
    graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
    g = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --date=short
    st = status
    co = checkout
    ci = commit
    now = rev-parse --abbrev-ref HEAD
    fetch-all = fetch -a --recurse-submodules

[filter "cleanup-source"]
    clean = /usr/local/bin/format-source.py

[push]
    default = current

#[pull]
#   rebase = true

format-source.pyはコミット時にタブや改行コードをよしなに変換してくれるツールで、自作です。
一人で開発する場合は必ず使っていますが、チームで開発する場合にはメンバー全員に設定してもらうこともあるし、IDEの設定でカバーすることもあるし、ケースバイケースですね。

/usr/local/bin/format-source.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
from optparse import OptionParser
import tempfile
from contextlib import closing
import os
import sys

def format_source(s):
    return s.rstrip().expandtabs(4) + "\n"

def format_file(f, fw):
    for line in f:
        fw.write(format_source(line))

parser = OptionParser()
(options, args) = parser.parse_args()
if len(args) > 0:
    for filename in args:
        fd, temp_filepath = tempfile.mkstemp()
        with open(filename, 'rb') as f:
            with closing(os.fdopen(fd, "wb")) as fw:
                format_file(f, fw)
        os.rename(temp_filepath, filename)
else:
    format_file(sys.stdin, sys.stdout)

最近Gitの設定で重要だと思っているのは、push.defaultの設定で、想定外のブランチをpushしてしまってあわあわするのを防ぐために必ずデフォルトの設定から変更しておきます。

git graph はなかったら生活できません。本家に入らないかなw

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