# git stash destroys hard links

3 messages from 2012-05-22 to 2012-05-22. Participants: Steven Penny, Junio C Hamano, Angus Hammond.
Thread: https://gitlist.dev/t/30584

## Steven Penny, 2012-05-22 04:24

Subject: git stash destroys hard links
Message-ID: <CAAXzdLWadNg9d_i8fZTawaxYm3ytcGCT4pzeth=LxrQYEO-3ww@mail.gmail.com>
URL: https://gitlist.dev/e/CAAXzdLWadNg9d_i8fZTawaxYm3ytcGCT4pzeth%3DLxrQYEO-3ww%40mail.gmail.com

```
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, 2012-05-22 17:41

Subject: Re: git stash destroys hard links
Message-ID: <7v62bo5d0z.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v62bo5d0z.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAAXzdLWadNg9d_i8fZTawaxYm3ytcGCT4pzeth=LxrQYEO-3ww@mail.gmail.com>

```
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, 2012-05-22 17:52

Subject: Re: git stash destroys hard links
Message-ID: <CAOBOgRYtMi38f63G2Nzd3--FsmN0F8geFi-AHxL2L2MMHWHFHA@mail.gmail.com>
URL: https://gitlist.dev/e/CAOBOgRYtMi38f63G2Nzd3--FsmN0F8geFi-AHxL2L2MMHWHFHA%40mail.gmail.com
In-Reply-To: <CAAXzdLWadNg9d_i8fZTawaxYm3ytcGCT4pzeth=LxrQYEO-3ww@mail.gmail.com>

```
>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

```
