設定ファイルをgitで管理する
動機
設定ファイルを変更したことを忘れがちなので、そのままバージョン管理をしてしまおうと思ってやってみた。
やり方
http://1-byte.jp/2011/01/04/home_with_git/を参考にした。
管理するファイルを決める
設定ファイルの中でもなにを管理したいかなと思って、ファイルを一覧表示した。
$ ls -al . . .
シェルとか、エディタの設定ファイルを抽出してみた。これらを管理してみよう。
.bashrc .gitconfig .gitignore .gvimrc .hgignore .hgrc .screenrc .vim/ .vimrc .zshrc
設定ファイルをgit管理下に入れる
設定ファイルをgit管理下に入れるということは、ホームディレクトリをgit管理下に入れるということ。やってみる。
$ cd ~ $ git init fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions
なんかエラーが出てあせったけど、とりあえず無視でだいじょうぶ。
このままだと、すべてのファイルがgitの管理下に入ってしまうので、.gitignoreというファイルを作って、無視するファイルと管理するファイルを設定する。
.gitignore
# I am selective about what I want to revision, you may not want this. /* # You probably want to ignore all the "dot" files in your home # directory, since they mostly contain local application state data. /.* # but... some dot files you probably do *not* want ignored are # listed here: !/.bashrc !/.gitconfig !/.gitignore !/.gvimrc !/.hgignore !/.hgrc !/.screenrc !/.vim !/.vimrc !/.zshrc
設定できたか確認するには、コマンドを打って確認する。
$ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .bashrc # .gitconfig # .gitignore # .gvimrc # .hgignore # .hgrc # .screenrc # .vim/ # .vimrc # .zshrc
これでよければ、インデックスにファイルを追加する。
$ git add .
最後にコミットする。
$ git commit -a
これで設定ファイルがgit管理下に入った〜。