2

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?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
ilhan
  • 8,700
  • 35
  • 117
  • 201

3 Answers3

4

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 archive behaves 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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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-commit hook. 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 (including git archive as 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-receive hook. It gets invoked on a server repo when a new version was pushed. From here, the process is pretty much the same as for the post-commit hook.

For a deeper discussion on the hooks, have a look at the Git Book and the reference:

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
0

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 git@github.com: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

gagarine
  • 4,190
  • 2
  • 30
  • 39