便利で使ってるDropboxですけど、どこかで誤ってファイルを消すと、同期しているすべてのマシンでそのファイルが消えてしまうので、同期とは別にバックアップがあった方が安心です。
どこかのマシンでcronとtarとかrsyncでバックアップしても良いのですが、何世代バックアップ取るかとか考えると面倒です。
そこで、gitを使えば履歴管理もできて便利だと考えました。
gitのリポジトリは、Dropboxディレクトリに置くわけにはいかないので、外に置くことになります。
最初、Dropboxディレクトリの親でgit initすることを考えたのですが、それだとホームディレクトリ全体が対象になってしまっていまいちです。
なので、gitのworking tree機能を使って、外に.gitディレクトリを作ることにします。
あ、環境はmacです。
% cd ~/Dropbox
% git init --separate-git-dir ~/.dropbox.git
続いて、~/Dropbox/.gitignoreを以下の内容で作ります。
.DS_Store
.dropbox
.dropbox.cache
.sync
Icon^M^M
/vimperator/vimperator-plugins
おもむろにgit add、そしてcommit
% git add .
% git commit -m "initial commit"
Dropboxの中に他の.gitディレクトリがあると、addするときに以下のような警告が出る。
warning: adding embedded git repository: vimperator/vimperator-plugins
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> vimperator/vimperator-plugins
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached vimperator/vimperator-plugins
hint:
hint: See "git help submodule" for more information.
submoduleとして扱うこともないので、後者の指示の通りgit rmした。何故か、-fオプションが必要だったけど。→結局、.gitignoreに追加することにした。
後は、気がむいたときに git commit -aとかすれば良い。
ちなみに、.gitignoreの意味は以下。
- .DS_Store →説明不要ですよね?
- .dropbox →dropboxが作るディレクトリ
- .dropbox.cache →同上
- .sync →Resilio syncが作るディレクトリ?
- Icon^M^M →アイコン?emacsだったらCtrl + q/Ctrl + mを2回、vimだったらCtrl + v/Ctrl + mを2回。(git statusの画面とかだと、Icon\rと表示されるので、最初何も考えずに\rとか^Rとか書いてなんでうまく行かないんだろうと悩んだ。\r\n→^M^Jでしたね。)
- /vimperator/vimperator-plugins →このディレクトリに.gitがあるので。
このやり方だと、~/Dropbox/.git に以下の内容が書かれるので、.dropbox.gitがないマシンでgitコマンドを叩くと悲しいことになるけど、叩かなければ良いのです。
gitdir: /Users/<ユーザ名>/.dropbox.git
参考にしたところ