Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting files from hook in bare git repository

Tags:

git

linux

So, my situation is the following: I want to maintain my website using emacs-muse mode. For transferring the website (and version control), I want to use git. So I would create a hook in the remote (bare) repository that automatically copies the HTML subdir to the web directory. How can I do that from a hook? Also note that the whole directory contains a lot of files, so I can't export the whole directory.

Any help welcome.

like image 310
jeeger Avatar asked Jan 20 '09 11:01

jeeger


People also ask

How do I export a file from git?

There is no "git export" command, so instead you use the "git archive" command. By default, "git archive" produces its output in a tar format, so all you have to do is pipe that output into gzip or bzip2 or other.

How do I export a git repository project?

Exporting a RepositoryStep 1: Go to your git bash. and then to the repo you want to extract or export. Here, we are going to export this repo named 'Ada August-a Challenge' and it's main branch. Step 2: Now export it to your preferred format and location, here we will export it to the same location in .

What is the git command to create the archive files?

The git archive command is a Git command line utility that will create an archive file from specified Git Refs like, commits, branches, or trees.


2 Answers

You can use git archive, as it takes a path command. So, in your post-update hook you can do something like

git archive $SHA HTML | (cd dir/where/html/should/go && tar x)

this first creates a tarball of the subdir, and pipes that tarball to a tar command to untar it in the specified directory

like image 151
Pieter Avatar answered Sep 29 '22 15:09

Pieter


(just a suggestion, as it may not be applicable in your exact configuration)

You might consider adopting this Web-Focused Git Workflow which, instead of copying, does push your repo directly on the web directory.

http://joemaller.com/wordpress/wp-content/uploads/2008/11/hub-prime2.jpg
(From Joe MALLER)


Less complicated: Using Git to maintain your website (Daniel MIESSLER):

http://dmiessler.com/wp-content/uploaded_content/2008/12/git-tree.gif

Daniel MIESSLER has an updated version of that same process:

http://danielmiessler.com/wp-content/uploads/2011/07/git_website_1.png

Other suggestions are available at this SO question, like this post-update script mentioned in the Git FAQ.

like image 36
VonC Avatar answered Sep 29 '22 14:09

VonC