Reputation: 21168
I read GIT documentation, but couldn't figure out how to just simply copy newest version of code to another directory (or deploy it). Of course I could just simply copy -r code /path/to/another/dir
, but then it copies all other files that are created by GIT. And I don't need that. So is there a simple way to just copy raw files without all those hidden files (or copies of original files)?
Upvotes: 7
Views: 4477
Reputation:
Assuming you have a standard setup for your Git repo, you could just copy everything in your project's root, but exclude the .git
subdirectory.
Apparently you can do this with a bash terminal using rsync
:
rsync -av --exclude='.git' source destination
but I'm not sure how you could do it with Windows copy
.
Another option is to use git archive
:
git archive --format zip --output "output.zip" master -0
will give you an uncompressed archive (-0
is the flag for uncompressed). The issue with this is that you then have to extract the files from the archive.
If you have access to Unix tools in something like a bash shell or Cygwin, you could also use these Unix tools in janos's answer. See also How to do a “git export” (like “svn export”).
# Option 3: Use git ls-files
Edit actually having problems with this one because I'm passing the arguments to cp
in the wrong order (files as destination directories instead of sources), so scratch this for now.
Another option is to get a list of all the files that Git is tracking in your working copy, then pass them as an argument to a copy command. Here is an example with Unix cp
:
git ls-files | xargs cp <destination-root>
Upvotes: 5
Reputation: 124704
This is one way to do it:
mkdir /path/to/target/dir
git archive master | tar x -C /path/to/target/dir
The git archive
command is normally to generate an archive file from the content of the repository. It dumps to archive to standard output, which you normally redirect to a file. Here, we subvert the command a bit: instead of redirecting, we immediately extract it, into the specified directory. The target directory must be created first.
That said, you seem to want this for deploying your project. Personally I use Git itself to deploy projects. That way you can upgrade and roll back easily using Git commands. Granted, the .git
directory will exist in the deployment directory, on the other hand, a simply copy will not delete files that were removed in the repository, they will remain at the destination.
Finally, you might be interested in my personal favorite: using a post-receive hook to deploy projects remotely.
Upvotes: 7