刚刚遇到了一个奇怪的情况du
。以一种方式放置参数会得到:
$ du -s htdocs/.git/ feuerkraft/.git/ media/.git/
40564 htdocs/.git/
40740 feuerkraft/.git/
204 media/.git/
以不同的顺序放置它们会改变最后一个目录的大小:
$ du -s media/.git/ htdocs/.git/ feuerkraft/.git/
40696 media/.git/
40564 htdocs/.git/
248 feuerkraft/.git/
这些都应该是常规目录:
$ ls -l */.git -d -i
4891918 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:41 feuerkraft/.git
4892896 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:44 htdocs/.git
4893874 drwxrwxr-x 1 ingo ingo 138 Mar 28 08:42 media/.git
手动操作可得到:
$ for i in htdocs/.git/ feuerkraft/.git/ media/.git/; do du -s "${i}"; done
40564 htdocs/.git/
40740 feuerkraft/.git/
40696 media/.git/
当我复制目录时,cp -axv
问题仍然存在,如果我复制目录,问题cp -rxv
就会消失。
深层发掘:
$ du -s feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack | wc -l
2
$ ls feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack | wc -l
3
du
如果给出三个文件,则仅列出 2 个,ls
列出 3 个。
文件系统是btrfs
。这是错误还是与压缩/写时复制或其他有关的问题?
答案1
这解释了这一点:
$ ls -l feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack -i
13150428 -r--r--r-- 2 ingo ingo 41191354 Mar 15 14:14 feuerkraft/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack
13151244 -r--r--r-- 1 ingo ingo 41197513 Mar 28 08:44 htdocs/.git/objects/pack/pack-31a80589fbb132827d19b718c07aba1aa6bb9c02.pack
13150428 -r--r--r-- 2 ingo ingo 41191354 Mar 15 14:14 media/.git/objects/pack/pack-26b69bdec4b3fd894bf7984d23e1938b522e6d53.pack
feuerkraft
和文件media
指向相同的 inode,即硬链接。这是git clone
和 的一个功能,在手册页中有记录:
$ man git clone
...
--no-hardlinks
Force the cloning process from a repository on a local filesystem to copy
the files under the .git/objects directory instead of using hardlinks.
This may be desirable if you are trying to make a back-up of your
repository.
这也解释了为什么git
将包文件设置为只读,一直对此感到疑惑。du
还有一个选项可以将硬链接计算两次:
$ man du
...
-l, --count-links
count sizes many times if hard linked
这给出了预期的结果:
$ du -ls media/.git/ htdocs/.git/ feuerkraft/.git/
40696 media/.git/
40564 htdocs/.git/
40740 feuerkraft/.git/