threads / discuss / 30584

git stash destroys hard links

Subject: git stash destroys hard links

## tl;dr

3 messages between May 22, 2012 and May 22, 2012.

replies: 2people: 3as markdown or json

Steven Penny· May 22, 2012, 04:24 UTC · lore

I dont know if this is even fixable, but I wanted to at least mention it. Performing a git stash will destroy any hard links and replace them with simply a copy of the file.

$ mkdir test $ cd test $ git init $ touch foobar.sh $ git add -A $ git commit -m 'first commit'

$ ln foobar.sh foobar-link.sh

$ ls -l total 0 -rw-r--r-- 2 Steven None 0 May 21 23:18 foobar.sh -rw-r--r-- 2 Steven None 0 May 21 23:18 foobar-link.sh

$ git stash -u $ git stash pop

$ ls -l total 0 -rw-r--r-- 1 Steven None 0 May 21 23:18 foobar.sh -rw-r--r-- 1 Steven None 0 May 21 23:18 foobar-link.sh

Junio C Hamano· May 22, 2012, 17:41 UTC · re: Steven Penny · lore

Re: git stash destroys hard links

Steven Penny <svnpenn@gmail.com> writes:
> I dont know if this is even fixable, but I wanted to at least mention it.

I do not think there is anything specific to stash. Whenever we write out results of an operation to a file in the working tree, we first unlink(2) and then creat(2), which essentially breaks hardlinked files and avoids updating some _other_ paths that share the underlying file with the updated path.

Angus Hammond· May 22, 2012, 17:52 UTC · re: Steven Penny · lore

Re: git stash destroys hard links

>From the very quick and unscientific test that I just did, it doesn't

appear that git commits hard links, it just collapses them into separate regular files (presumably to avoid changes in one place mucking things up elsewhere without git knowing about it). I don't think it makes much sense to stash hardlinks if the policy is to forget them in commits. Thanks Angus

← back to recent threads