Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git是否对同一磁盘上的远程设备使用硬链接?_Git_Hardlink - Fatal编程技术网

git是否对同一磁盘上的远程设备使用硬链接?

git是否对同一磁盘上的远程设备使用硬链接?,git,hardlink,Git,Hardlink,我有时使用两个同级目录,它们都包含相同的存储库。使用 git remote add sibling ../the-other-directory 我只需通过 git fetch sibling git cherry-pick sibling/a-branch 这是非常实际的,但是我对硬链接有一个顾虑: 如果存储库共享文件,则破坏其中一个存储库也会破坏另一个存储库。损坏的存储库是我已经经历过的事情,我确信节省几兆字节和几毫秒是不值得的 git从同一分区上的存储库获取数据时是否使用硬链接 如果

我有时使用两个同级目录,它们都包含相同的存储库。使用

git remote add sibling ../the-other-directory
我只需通过

git fetch sibling
git cherry-pick sibling/a-branch
这是非常实际的,但是我对硬链接有一个顾虑:

如果存储库共享文件,则破坏其中一个存储库也会破坏另一个存储库。损坏的存储库是我已经经历过的事情,我确信节省几兆字节和几毫秒是不值得的

  • git从同一分区上的存储库获取数据时是否使用硬链接
  • 如果是这样的话,有没有办法防止这种情况发生(比如
    ——没有硬链接)

不使用硬链接的另一个好处是有一个额外的备份,可以不费吹灰之力地经常更新。

Git在克隆时使用硬链接,但在获取时不使用硬链接。也就是说,当您通过
git remote add foo../where
添加您的遥控器,然后
git fetch foo
,您将获得副本,不是硬链接。

使用以下脚本进行测试表明,通过
git init
+
git remote add
+
git fetch
进行伪克隆不会创建到源存储库的硬链接:

硬链接测试

#!/usr/bin/env bash
tmpdir="$(mktemp -d)"
trap "rm -rf $tmpdir" EXIT
cd "$tmpdir"
set -x
git clone https://github.com/dictcp/awesome-git testrepo
git clone testrepo testrepo.localclone
mkdir testrepo.pseudoclone
cd testrepo.pseudoclone
git init
git remote add sibling ../testrepo
git fetch sibling
cd ..
ls -1 -i testrepo*/.git/objects/a0
$ ls -1 -i testrepo*/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
$ ./hardlinktest 
+ git clone https://github.com/dictcp/awesome-git testrepo
Cloning into 'testrepo'...
remote: Counting objects: 58, done.
remote: Total 58 (delta 0), reused 0 (delta 0), pack-reused 58
Unpacking objects: 100% (58/58), done.
Checking connectivity... done.
+ git clone testrepo testrepo.localclone
Cloning into 'testrepo.localclone'...
done.
+ mkdir testrepo.pseudoclone
+ cd testrepo.pseudoclone
+ git init
Initialized empty Git repository in /tmp/tmp.ZWoH0OTA1P/testrepo.pseudoclone/.git/
+ git remote add sibling ../testrepo
+ git fetch sibling
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 58 (delta 17), reused 0 (delta 0)
Unpacking objects: 100% (58/58), done.
From ../testrepo
 * [new branch]      master     -> sibling/master
+ cd ..
+ ls -1 -i testrepo/.git/objects/a0 testrepo.localclone/.git/objects/a0 testrepo.pseudoclone/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
+ rm -rf /tmp/tmp.ZWoH0OTA1P
输出的相关部分

#!/usr/bin/env bash
tmpdir="$(mktemp -d)"
trap "rm -rf $tmpdir" EXIT
cd "$tmpdir"
set -x
git clone https://github.com/dictcp/awesome-git testrepo
git clone testrepo testrepo.localclone
mkdir testrepo.pseudoclone
cd testrepo.pseudoclone
git init
git remote add sibling ../testrepo
git fetch sibling
cd ..
ls -1 -i testrepo*/.git/objects/a0
$ ls -1 -i testrepo*/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
$ ./hardlinktest 
+ git clone https://github.com/dictcp/awesome-git testrepo
Cloning into 'testrepo'...
remote: Counting objects: 58, done.
remote: Total 58 (delta 0), reused 0 (delta 0), pack-reused 58
Unpacking objects: 100% (58/58), done.
Checking connectivity... done.
+ git clone testrepo testrepo.localclone
Cloning into 'testrepo.localclone'...
done.
+ mkdir testrepo.pseudoclone
+ cd testrepo.pseudoclone
+ git init
Initialized empty Git repository in /tmp/tmp.ZWoH0OTA1P/testrepo.pseudoclone/.git/
+ git remote add sibling ../testrepo
+ git fetch sibling
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 58 (delta 17), reused 0 (delta 0)
Unpacking objects: 100% (58/58), done.
From ../testrepo
 * [new branch]      master     -> sibling/master
+ cd ..
+ ls -1 -i testrepo/.git/objects/a0 testrepo.localclone/.git/objects/a0 testrepo.pseudoclone/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
+ rm -rf /tmp/tmp.ZWoH0OTA1P
这意味着文件
testrepo.localclone/.git/objects/a0/cdfa472f8212a02a3edeb941868d651749d
是指向
testrepo/.git/objects/a0/cdfa472f82212a2a3edeb941868d651749d
的硬链接-它们的inode值相同(我的测试运行为417590,但您的里程数当然会有所不同)。
testrepo.pseudoclone
存储库中相应文件的inode值(537341)告诉我们它是一个独立副本

全输出

#!/usr/bin/env bash
tmpdir="$(mktemp -d)"
trap "rm -rf $tmpdir" EXIT
cd "$tmpdir"
set -x
git clone https://github.com/dictcp/awesome-git testrepo
git clone testrepo testrepo.localclone
mkdir testrepo.pseudoclone
cd testrepo.pseudoclone
git init
git remote add sibling ../testrepo
git fetch sibling
cd ..
ls -1 -i testrepo*/.git/objects/a0
$ ls -1 -i testrepo*/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
$ ./hardlinktest 
+ git clone https://github.com/dictcp/awesome-git testrepo
Cloning into 'testrepo'...
remote: Counting objects: 58, done.
remote: Total 58 (delta 0), reused 0 (delta 0), pack-reused 58
Unpacking objects: 100% (58/58), done.
Checking connectivity... done.
+ git clone testrepo testrepo.localclone
Cloning into 'testrepo.localclone'...
done.
+ mkdir testrepo.pseudoclone
+ cd testrepo.pseudoclone
+ git init
Initialized empty Git repository in /tmp/tmp.ZWoH0OTA1P/testrepo.pseudoclone/.git/
+ git remote add sibling ../testrepo
+ git fetch sibling
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 58 (delta 17), reused 0 (delta 0)
Unpacking objects: 100% (58/58), done.
From ../testrepo
 * [new branch]      master     -> sibling/master
+ cd ..
+ ls -1 -i testrepo/.git/objects/a0 testrepo.localclone/.git/objects/a0 testrepo.pseudoclone/.git/objects/a0
testrepo/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.localclone/.git/objects/a0:
417590 cdfa472f2bf8212a02a3edeb941868d651749d

testrepo.pseudoclone/.git/objects/a0:
537341 cdfa472f2bf8212a02a3edeb941868d651749d
+ rm -rf /tmp/tmp.ZWoH0OTA1P