3

The title seems a bit weird, so a bit of background:

I got a couples of local git repos, and found myself wanting to make a backup. Two method came to mind, git bundle and tar (aware there many other but i wanted something "simple" and that would make repo packed in a "single file")

  • Using Tar

The command i tried was

tar cvf gitrepo.tar gitrepo/

Now, this works at first glance, but if i extract it somewhere, a couple of oddities appear, such as:

the git config (the one in .git/config) seems to not be the same one that was put in the tar, but an "older" version. eg: if i edit the config and tar it, then extract it, the config won't have the latest change for whatever reason...

Beside that, everything else seems to work, though i didn't check if other files in the .git folder had similar oddities as the config file.

  • Using git bundle

The two command i tried were:

git bundle create repo.bundle

and

git bundle create repo.bundle --all

The first command work on first glance, but i then noticed it didn't had all the branch, given i didn't use the --all flag.

The second command work on first glance (again), but, if i git clone said bundle, it end up not containing all the files that are committed in the non-bundled/original local repo...

I thought that the "missing files" were in .git, so i looked for the biggest file there, and found one in .git/objects/pack...so i unpacked it using the following command:

cd "$@"/.git/objects/pack ; mkdir ~/SAMPLE; mv *.pack ~/SAMPLE; git unpack-objects < ~/SAMPLE/*.pack; rm -rf ~/SAMPLE

$@ being the name of the local repo that was cloned from the git bundle. I didn't solve the above issue but i did notice that some of the commit history was restored, albeit with files still missing from the original repo.

So I'm confused at to how correctly backing up my local git repo (preferably in a single file) while still retaining latest change on file and without missing files? (as in, all commit history, branch, etc)

7
  • Do you also have ~/.gitconfig file with global Git settings? This could explain why your first attempt seemed to fail.
    – Kusalananda
    Mar 20, 2021 at 18:16
  • I don't :/ that's also why i find it weird that tar didn't work like it's supposed to. @Kusalananda Mar 20, 2021 at 18:19
  • 4
    Well, I've never had tar modify a file for me, which is what it is doing according to your description. Try again. The action of creating a copy of a repository, or an archive, will not modify the repository from what's there.
    – Kusalananda
    Mar 20, 2021 at 18:22
  • I never had this happen before. I tried, even on a completely new live distro, where i just moved the target git repo and installed git. The same thing happen, even in a oneline : md5sum gitrepo/.git/config ; echo "test" >> gitrepo/.git/config ; tar cvf gitrepo.tar gitrepo/ ; rm -rf gitrepo/ ; tar xvf gitrepo.tar ; md5sum gitrepo/.git/config @Kusalananda Mar 20, 2021 at 18:34
  • I tried the above oneliner with cat instead of md5sum to make sure this was happening too. it seems to not take into account the change in the file and just happen to be an "older version" or the file before i modified it when extracting. Mar 20, 2021 at 18:36

1 Answer 1

2

Seems like tar work as expected if i move the tar before extracting it:

mv gitrepo.tar otherdir/
cd otherdir ; tar xvf gitrepo.tar

As an alternative, zip seems to work fine without moving the archive first:

zip -Zs -r -FS gitrepo.zip gitrepo/

The above does zip without compression.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .