I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git
repository directory. There are at least three methods I know of:
git clone
followed by removing the.git
repository directory.git checkout-index
alludes to this functionality but starts with "Just read the desired tree into the index..." which I'm not entirely sure how to do.git-export
is a third party script that essentially does agit clone
into a temporary location followed byrsync --exclude='.git'
into the final destination.
None of these solutions really strike me as being satisfactory. The closest one to svn export
might be option 1, because both those require the target directory to be empty first. But option 2 seems even better, assuming I can figure out what it means to read a tree into the index.
I think @Aredridel's post was closest, but there's a bit more to that - so I will add this here; the thing is, in
svn
, if you're in a subfolder of a repo, and you do:then
svn
will export all files that are under revision control (they could have also freshly Added; or Modified status) - and if you have other "junk" in that directory (and I'm not counting.svn
subfolders here, but visible stuff like.o
files), it will not be exported; only those files registered by the SVN repo will be exported. For me, one nice thing is that this export also includes files with local changes that have not been committed yet; and another nice thing is that the timestamps of the exported files are the same as the original ones. Or, assvn help export
puts it:To realize that
git
will not preserve the timestamps, compare the output of these commands (in a subfolder of agit
repo of your choice):... and:
... and I, in any case, notice that
git archive
causes all the timestamps of the archived file to be the same!git help archive
says:... but apparently both cases set the "modification time of each file"; thereby not preserving the actual timestamps of those files!
So, in order to also preserve the timestamps, here is a
bash
script, which is actually a "one-liner", albeit somewhat complicated - so below it is posted in multiple lines:Note that it is assumed that you're exporting the contents in "current" directory (above,
/media/disk/git_svn/subdir
) - and the destination you're exporting into is somewhat inconveniently placed, but it is inDEST
environment variable. Note that with this script; you must create theDEST
directory manually yourself, before running the above script.After the script is ran, you should be able to compare:
... and hopefully see the same timestamps (for those files that were under version control).
Hope this helps someone,
Cheers!
If you need submodules as well, this should do the trick: https://github.com/meitar/git-archive-all.sh/wiki
I have hit this page frequently when looking for a way to export a git repository. My answer to this question considers three properties that svn export has by design compared to git, since svn follows a centralized repository approach:
Exporting a certain branch using svn is accomplished by specifying the appropriate path
When building a certain release it is useful to clone a stable branch as for example
--branch stable
or--branch release/0.9
.git archive
also works with remote repository.To export particular path inside the repo add as many paths as you wish as last argument to git, e.g.:
Bash-implementation of git-export.
I have segmented the .empty file creation and removal processes on their own function, with the purpose of re-using them in the 'git-archive' implementation (will be posted later on).
I have also added the '.gitattributes' file to the process in order to remove un-wanted files from the target export folder. Included verbosity to the process while making the 'git-export' function more efficient.
EMPTY_FILE=".empty";
My preference would actually be to have a dist target in your Makefile (or other build system) that exports a distributable archive of your code (.tar.bz2, .zip, .jar, or whatever is appropriate). If you happen to be using GNU autotools or Perl's MakeMaker systems, I think this exists for you automatically. If not, I highly recommend adding it.
ETA (2012-09-06): Wow, harsh downvotes. I still believe it is better to build your distributions with your build tools rather than your source code control tool. I believe in building artifacts with build tools. In my current job, our main product is built with an ant target. We are in the midst of switching source code control systems, and the presence of this ant target means one less hassle in migration.