0

We have created git bare in the shared mode and created the data repository by cloning the git bare.

As both git bare repo and git data repo lies on the same file system, it seems the object files are hardlinked to save space.

I wanted to backup the git bare repository now and delete the data repository.

I am afraid that deleting the data repository will leave the bare repository in the stale state due to the object files being hardlinked.

Is there a way where I can copy all the object files from the data repo that are hardlinked to the bare repo, so that I can delete the data repo and backup the repo?

Your help is much appreciated.

user298800
  • 421
  • 1
  • 4
  • 5

1 Answers1

3

Don't be afraid. You can simply delete one of the copies without losing the other. There is not one "original" and one "copy". Instead, both are "original" files that will continue to exist without the other side. Only the file's content is shared on disc and thus stored only once.

That's not a feature of Git. It's exactly the way how hardlinks have always worked (in contrast to softlinks/symlinks, which have a clear distinction between the link file and the file linked to). It is also the reason why hardlinks don't work across filesystem boundaries within one machine. And it is also the reason why functions (in several programming languages) that remove a file in UN*X-like systems are often called "unlink" instead of "remove".

Of course, since the file contents are stored on disc only once, both copies will change if you edit one of them. But that is no problem. Git never _changes_ files in the object database, if only adds them (and occasionally removes (= unlinks) them on garbage collection). Since object files in Git are immutable, the fact that they are hardlinked to other immutable files doesn't matter at all (apart from saving disc space), which is why the -l option is now the default in git-clone.

Haxe
  • 31
  • 1