'Git repository without history
Is it possible to have a Git repository without history? For example, I have a local Git repository where I work and I want to push the latest version to the production server. No history should be stored on the production server. How can I do that?
Solution 1:[1]
You can see if the command git archive fits the bill:
Creates an archive of the specified format containing the tree structure for the named tree, and writes it out to the standard output.
If<prefix>is specified it is prepended to the filenames in the archive.
git archivebehaves differently when given a tree ID versus when given a commit ID or tag ID.
- In the first case the current time is used as the modification time of each file in the archive.
- In the latter case the commit time as recorded in the referenced commit object is used instead.
Once you have created an archive, you can copy it and unzip it on the server side: no git required on the server.
Since you have to copy only one file (instead of a large number of files with rsync over your working tree), the transfer is easier.
Solution 2:[2]
What you want is a post-receive or post-commit hook:
If you're purely working local and never push anything anywhere, use the
post-commithook. It gets triggered after each commit and gives you the opportunity to do whatever you want, including pushing your lastest changed files to somewhere using whatever tool you want to (includinggit archiveas VonC recommends)If you're pushing 'release' versions of your work to a remote server (or another local blessed repo, doesn't matter for this case), use the
post-receivehook. It gets invoked on a server repo when a new version was pushed. From here, the process is pretty much the same as for thepost-commithook.
For a deeper discussion on the hooks, have a look at the Git Book and the reference:
Solution 3:[3]
You can use --depth to create a shallow clone with a history truncated to the specified number of commits.
To only retrieve the last commit use --depth 1.
git clone [email protected]:account/repository.git --depth 1
If you need the recent 5 commits, you’ll specify --depth 5
Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.
From: https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | VonC |
| Solution 2 | Community |
| Solution 3 | gagarine |
