git引发的inode变化

Submitted by Dot on Tue, 08/23/2016 - 17:20

本文暂只说明现象,原因则有待研究。

我们删掉git目录下的一个文件foo1,如果foo1是其他文件foo的硬链接,此时虽然可以用git checkout foo1恢复文件,但恢复出来的这个foo1拥有的是不同的inode,和目标文件foo已失去了对应关系,俨然一个新文件。这倒不难理解。

但如果说这一举动会导致目标文件foo的inode也发生变化,就有些匪夷所思了。
来看看下面这个例子。

  • 当前目录/home/Dot/emma/src/是一个git文件夹,li是ls -i的alias
  • /home/Dot/emma/src/bash/dotr是/home/Dot/.local/bin/dotr的硬链接,在开始它们的inode都是9308040
  • 删掉/home/Dot/emma/src/bash/dotr
  • 然后用git checkout bash/dotr恢复;恢复出来的bash/dotc的inode已经变成了8652286,显然已不再是/home/Dot/.local/bin/dotr的链接,编辑两者应该互不影响
  • 但奇怪的是在用vi随意编辑原文件/home/Dot/.local/bin/dotr后,它的inode变成了9308039;更有趣的是,再次用vi编辑,又变回了9308040,如此循环;
  • bash/dotr竟然也一样,vi编辑后变成8652288,再编辑变成8652287,之后就一直循环;
  • 这种现象在重新建立链接(ln ~/.local/bin/dotr bash/dotr)后才结束;
  • arnold在这里提供了线索;

[[email protected] src]$ pwd
/home/Dot/emma/src
[[email protected] src]$ alias li="ls -i"
[[email protected] src]$ li ~/.local/bin/dotr 
9308040 /home/Dot/.local/bin/dotr
[[email protected] src]$ li bash/dotr 
9308040 bash/dotr
[[email protected] src]$ rm bash/dotr
[[email protected] src]$ git checkout bash/dotr
[[email protected] src]$ li bash/dotr
8652286 bash/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308040 /home/Dot/.local/bin/dotr
[[email protected] src]$ vim ~/.local/bin/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308039 /home/Dot/.local/bin/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308039 /home/Dot/.local/bin/dotr
[[email protected] src]$ vim ~/.local/bin/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308040 /home/Dot/.local/bin/dotr
[[email protected] src]$ vim bash/dotr 
[[email protected] src]$ li bash/dotr
8652288 bash/dotr
[[email protected] src]$ vim bash/dotr
[[email protected] src]$ li bash/dotr
8652287 bash/dotr
[[email protected] src]$ li bash/dotr
8652287 bash/dotr
[[email protected] src]$ vim bash/dotr
[[email protected] src]$ 
[[email protected] src]$ li bash/dotr
8652287 bash/dotr
[[email protected] src]$ vim bash/dotr 
[[email protected] src]$ li bash/dotr 
8652288 bash/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308040 /home/Dot/.local/bin/dotr
[[email protected] src]$ vim ~/.local/bin/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308039 /home/Dot/.local/bin/dotr
[[email protected] src]$ vim ~/.local/bin/dotr
[[email protected] src]$ li ~/.local/bin/dotr 
9308040 /home/Dot/.local/bin/dotr

Tags

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.