シンボリックリンクのgitの差分調査と相対パスシンボリックリンク
6 min read
こんにちは、無能です。
git
でシンボリックリンクを張った時にどうなるか気になったのでやってみます。
パターン
/usr/bin/pwd
のハードリンクhardlink-pwd
/usr/bin/pwd
のシンボリックリンクln-s-link-pwd-usr-bin-pwd
./pwd
という名前のテキストファイル./pwd
のシンボリックリンクpwd-ln-s
実行バイナリのハードリンクが、git push
したあとにgit clone
するとどうなるか気になった(やらなくてもなんとなくで予想はつきますが。。。)のと、シンボリックリンクがgit
で管理されている上階層にある場合にも維持されるか気になったのでやってみます。
証跡
alleycat:[haturatu]:~/git$ mkdir gitlinks
alleycat:[haturatu]:~/git$ cd gitlinks/
alleycat:[haturatu]:~/git/gitlinks$ ls
alleycat:[haturatu]:~/git/gitlinks$ pwd > pwd
alleycat:[haturatu]:~/git/gitlinks$ ls
pwd
alleycat:[haturatu]:~/git/gitlinks$ cat pwd
/home/haturatu/git/gitlinks
alleycat:[haturatu]:~/git/gitlinks$ ln -s pwd pwd-ln-s
alleycat:[haturatu]:~/git/gitlinks$ ls
pwd pwd-ln-s
alleycat:[haturatu]:~/git/gitlinks$ which pwd
/usr/bin/pwd
alleycat:[haturatu]:~/git/gitlinks$ ln /usr/bin/p
Display all 354 possibilities? (y or n)
alleycat:[haturatu]:~/git/gitlinks$ ln /usr/bin/pw
pw-cli pw-dump pw-profiler pwconv pwmconfig
pw-config pw-link pw-reserve pwd pwunconv
pw-container pw-metadata pw-top pwdx
pw-dot pw-mon pwck pwhistory_helper
alleycat:[haturatu]:~/git/gitlinks$ ln /usr/bin/pwd hardlink-pwd
ln: 'hardlink-pwd' から '/usr/bin/pwd' へのハードリンクの作成に失敗しました: 許可されていない操作です
alleycat:[haturatu]:~/git/gitlinks$ sudo ln /usr/bin/pwd hardlink-pwd
指紋読取装置に右の人差し指をなぞってください
alleycat:[haturatu]:~/git/gitlinks$ ls
hardlink-pwd pwd pwd-ln-s
alleycat:[haturatu]:~/git/gitlinks$ ls -la
合計 48
drwxr-xr-x 2 haturatu haturatu 4096 1月 13 01:50 .
drwxr-xr-x 115 haturatu haturatu 4096 1月 13 01:48 ..
-rwxr-xr-x 2 root root 34944 8月 31 23:29 hardlink-pwd
-rw-r--r-- 1 haturatu haturatu 28 1月 13 01:48 pwd
lrwxrwxrwx 1 haturatu haturatu 3 1月 13 01:49 pwd-ln-s -> pwd
alleycat:[haturatu]:~/git/gitlinks$ chown haturatu:haturatu hardlink-pwd
chown: 'hardlink-pwd' の所有者を変更中: 許可されていない操作です
alleycat:[haturatu]:~/git/gitlinks$ sudo chown haturatu:haturatu hardlink-pwd
alleycat:[haturatu]:~/git/gitlinks$ which pwd
/usr/bin/pwd
alleycat:[haturatu]:~/git/gitlinks$ ls -la /usr/bin/pwd
-rwxr-xr-x 2 haturatu haturatu 34944 8月 31 23:29 /usr/bin/pwd
alleycat:[haturatu]:~/git/gitlinks$ echo "# git-ln-s-test" >> README.md
alleycat:[haturatu]:~/git/gitlinks$ git init
git add README.md
git commit -m "first commit"
git branch -M main
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/haturatu/git/gitlinks/.git/
[master (root-commit) 3853932] first commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
alleycat:[haturatu]:~/git/gitlinks$ git remote add origin git@github.com:haturatu/git-ln-s-test.git
alleycat:[haturatu]:~/git/gitlinks$ vim pwd
alleycat:[haturatu]:~/git/gitlinks$ git add .
alleycat:[haturatu]:~/git/gitlinks$ git commit -m "yo"
[main ca78a3e] yo
3 files changed, 3 insertions(+)
create mode 100755 hardlink-pwd
create mode 100644 pwd
create mode 120000 pwd-ln-s
alleycat:[haturatu]:~/git/gitlinks$ vim pwd-ln-s
alleycat:[haturatu]:~/git/gitlinks$ git commit -m "2"
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: pwd
no changes added to commit (use "git add" and/or "git commit -a")
alleycat:[haturatu]:~/git/gitlinks$ git add .
alleycat:[haturatu]:~/git/gitlinks$ git commit -m "2"
[main b3fd4ed] 2
1 file changed, 1 insertion(+)
alleycat:[haturatu]:~/git/gitlinks$ ls -la
合計 56
drwxr-xr-x 3 haturatu haturatu 4096 1月 13 01:53 .
drwxr-xr-x 115 haturatu haturatu 4096 1月 13 01:48 ..
drwxr-xr-x 9 haturatu haturatu 4096 1月 13 01:54 .git
-rw-r--r-- 1 haturatu haturatu 16 1月 13 01:53 README.md
-rwxr-xr-x 2 haturatu haturatu 34944 8月 31 23:29 hardlink-pwd
-rw-r--r-- 1 haturatu haturatu 38 1月 13 01:54 pwd
lrwxrwxrwx 1 haturatu haturatu 3 1月 13 01:49 pwd-ln-s -> pwd
alleycat:[haturatu]:~/git/gitlinks$ ln -s /usr/bin/pwd ln-s-link-pwd-usr-bin-pwd
alleycat:[haturatu]:~/git/gitlinks$ git add .
alleycat:[haturatu]:~/git/gitlinks$ git commit -m "3"
[main 119febf] 3
1 file changed, 1 insertion(+)
create mode 120000 ln-s-link-pwd-usr-bin-pwd
alleycat:[haturatu]:~/git/gitlinks$ git diff
alleycat:[haturatu]:~/git/gitlinks$ git push -u origin main
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 4 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (14/14), 13.37 KiB | 4.46 MiB/s, done.
Total 14 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:haturatu/git-ln-s-test.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
alleycat:[haturatu]:~/git/gitlinks$ ls -la
合計 56
drwxr-xr-x 3 haturatu haturatu 4096 1月 13 01:55 .
drwxr-xr-x 115 haturatu haturatu 4096 1月 13 01:48 ..
drwxr-xr-x 9 haturatu haturatu 4096 1月 13 01:56 .git
-rw-r--r-- 1 haturatu haturatu 16 1月 13 01:53 README.md
-rwxr-xr-x 2 haturatu haturatu 34944 8月 31 23:29 hardlink-pwd
lrwxrwxrwx 1 haturatu haturatu 12 1月 13 01:55 ln-s-link-pwd-usr-bin-pwd -> /usr/bin/pwd
-rw-r--r-- 1 haturatu haturatu 38 1月 13 01:54 pwd
lrwxrwxrwx 1 haturatu haturatu 3 1月 13 01:49 pwd-ln-s -> pwd
alleycat:[haturatu]:~/git/gitlinks$ sudo chown root:root hardlink-pwd
指紋読取装置に右の人差し指をなぞってください
指紋の検証に失敗しました
指紋読取装置に右の人差し指をなぞってください
指紋の検証に失敗しました
指紋読取装置に右の人差し指をなぞってください
alleycat:[haturatu]:~/git/gitlinks$ cd ..
alleycat:[haturatu]:~/git$ rm -rf gitl
gitlercuko/ gitlinks/
alleycat:[haturatu]:~/git$ rm -rf getlinks
alleycat:[haturatu]:~/git$ git clone git@github.com:haturatu/git-ln-s-test.git
Cloning into 'git-ln-s-test'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 14 (delta 2), reused 14 (delta 2), pack-reused 0 (from 0)
Receiving objects: 100% (14/14), 13.37 KiB | 6.69 MiB/s, done.
Resolving deltas: 100% (2/2), done.
alleycat:[haturatu]:~/git$ cd git-ln-s-test/
alleycat:[haturatu]:~/git/git-ln-s-test$ ls -la
合計 56
drwxr-xr-x 3 haturatu haturatu 4096 1月 13 01:59 .
drwxr-xr-x 116 haturatu haturatu 4096 1月 13 01:59 ..
drwxr-xr-x 8 haturatu haturatu 4096 1月 13 01:59 .git
-rw-r--r-- 1 haturatu haturatu 16 1月 13 01:59 README.md
-rwxr-xr-x 1 haturatu haturatu 34944 1月 13 01:59 hardlink-pwd
lrwxrwxrwx 1 haturatu haturatu 12 1月 13 01:59 ln-s-link-pwd-usr-bin-pwd -> /usr/bin/pwd
-rw-r--r-- 1 haturatu haturatu 38 1月 13 01:59 pwd
lrwxrwxrwx 1 haturatu haturatu 3 1月 13 01:59 pwd-ln-s -> pwd
結果
どうやら、ハードリンクはリンク自体はやっぱり解除されてinode
番号も変化しているので別ファイルという扱いになるようです。
そしてgit log
、GUI上で確認出来るのは私のpushしたログを見ていただければいいですがシンボリックリンクの元ファイルのみ差分は出ますがシンボリックリンク自体は差分はやっぱり出ません。
相対パスでシンボリックリンクを貼るには
作成時に相対パス指定すればOKです。
alleycat:[haturatu]:~/git/gitlinks$ ln -s ../../../../usr/bin/pwd pwd-rel
alleycat:[haturatu]:~/git/gitlinks$ ls -la
合計 56
drwxr-xr-x 3 haturatu haturatu 4096 1月 13 02:16 .
drwxr-xr-x 116 haturatu haturatu 4096 1月 13 01:59 ..
drwxr-xr-x 9 haturatu haturatu 4096 1月 13 01:56 .git
-rw-r--r-- 1 haturatu haturatu 16 1月 13 01:53 README.md
lrwxrwxrwx 1 haturatu haturatu 12 1月 13 02:08 ext4magic -> ../ext4magic
-rwxr-xr-x 2 root root 34944 8月 31 23:29 hardlink-pwd
lrwxrwxrwx 1 haturatu haturatu 12 1月 13 01:55 ln-s-link-pwd-usr-bin-pwd -> /usr/bin/pwd
-rw-r--r-- 1 haturatu haturatu 38 1月 13 01:54 pwd
lrwxrwxrwx 1 haturatu haturatu 3 1月 13 01:49 pwd-ln-s -> pwd
lrwxrwxrwx 1 haturatu haturatu 23 1月 13 02:16 pwd-rel -> ../../../../usr/bin/pwd