Git repository without history

点点圈 提交于 2021-02-18 17:49:29

问题


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?


回答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 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.




回答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-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:

  • http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
  • http://git-scm.com/docs/githooks


来源:https://stackoverflow.com/questions/27580782/git-repository-without-history

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!