git に、シンボリックリンクされたファイルを追加出来ない場合の対処方法

自分の作ったクラスを、gitHubなどに追加したい時に、クラス側とライブラリ側が別ファイルになったら、どちらかを変えた時に面倒な事ってありますよね。そのために最初、
[cc]
ln -s [source][/source] [destination]
[/cc]
のターミナルコマンドを使って、リンクを張っていたのですが、gitを使った時に、ファイルの内容ではなくて、シンボリックリンクの定義内容がgitにアップされてしまって、困りました。対処方法を見つけたので記述します。

日本語で検索してもあまり情報が見つからず、英語で検索したところ、いつもの stackoverflow に引っかかりました。
osx – Creating directory hard links in MacOS X? – Stack Overflow
TimeMachine の為に作られたという、ハードリンクという機能を使うことによって実現出来るそうです。

I have bundled up the suggested answer in a git rep if anybody is interested
https://github.com/selkhateeb/hardlink
I also noticed that unlink command does not work on snow leopard .. so I added an option to unlink
so simple once installed it can be used as follow:
to link:
hardlink source destination
to unlink:
hardlink -u destination

なので、gitHubからデータを取って来てやってみました。
selkhateeb/hardlink – GitHub
インストールは簡単
[cc]
git clone git://github.com/selkhateeb/hardlink.git
make
sudo make install
[/cc]
リンク方法は、
[cc]
to link: hardlink source destination
to unlink: hardlink -u destination
[/cc]
と、基本的にシンボリックリンクと同じような感じですね。
これをやってみたところ、うまくgitにも登録出来て、ライブラリ用のソースと、実プロジェクトのソースをリンクさせることが出来ました。

ただ,見た感じに、リンクしている様子が出なくて、片方を削除したら、相手も影響を受けるようなので、注意する必要がありますね。

「git に、シンボリックリンクされたファイルを追加出来ない場合の対処方法」への9件のフィードバック

  1. ハードリンクは単に同じファイルを複数ヶ所から参照するだけなので、それを作ったツリーではリンクになっているでしょうがcheckoutするとただのコピーになってしまいますよ?

    1. メッセージありがとうございます。ハードリンクで、同じファイルを複数箇所から参照して、ライブラリフォルダと、実際に使用しているフォルダ両方でgit管理したいので、目的は達成しています。gitに入った後に、checkoutして、ただのコピーになるのは問題ないです。

  2. 皆さん、こんにちは!

    Sorry, but I am completely noob.
    I am trying that command “hardlink source destination” and I’m getting: “Usage: hardlink source destination …..”

    Can someone please give me the right instructions how to make a hardlink.

    Why I need this?
    (I even dont know if is possible to hardlink folder from external disk to local disk.)
    Anyway…. iTunes. I have two external disks for media. One is for “audio” and the other is for “video”.
    I wanna have both external disks (or folders from both disks) pointed to local disk, /Users/’user’/Music/iTunes/iTunes Media/. So when I delete a media file in iTunes library, it should get deleted from external disk(s) too.
    And also, if I set iTunes Media folder location, to one of the external disks, some folders are created for iTunes, which I don’t like to have them there.

    OS X 10.7.2

    Thnx,
    Roger

    1. Hi Roger,

      You need to type “source” and “destination” correct
      hardlink source destination

      Like
      Tomos-MBP-17:~ tomohisa$ cd ~/Music/iTunes/
      Tomos-MBP-17:~ tomohisa$ hardlink /Volumes/BackUps/folder ./folder

      This…
      Let me know if you have further question…

  3. Hi admin,

    hm… I can’t get this to work :(

    Maybe if I give you my paths, than you can write me exact line:

    Local Disk: /Users/Roger/Music/iTunes/iTunes Media
    External drive 1: /Volumes/Media Audio/Music
    External drive 2: /Volumes/Media Video/Movies

    so, I wanna have external disks’ folders hardlinked to iTunes Media location.

    Thnx.

    1. how about this.

      hardlink /Users/Roger/Music/iTunes/iTunes\ Media/Music /Volumes/Media\ Audio/Music

      hardlink /Users/Roger/Music/iTunes/iTunes\ Media/Music /Volumes/Media\ Video/Movies

      Hope you get what you want. This “Hardlink” is made for the TimeMachine Backup, so it should work with external Drive.

  4. OK, I put brackets around long folders and hardlink’s output is now ‘hardlink: Cross-device link’.

    But still, there is no new folder created on destination.

    :confused

Roger へ返信する コメントをキャンセル

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください