简体   繁体   中英

How to construct a Git repository out of old code backups

I have quite recently started to use Git and think it is great. Earlier I did my backups by creating a zip-package of all code and named it with the current date (eg "MyAndroidApp -1- 2013-03-10.zip"). That method resulted in that I stored many duplicates of a lot code.

Now I want to take these backups and create Git repository out of them. I can't find if it is possible to set the date and time for the commit-stamp, is this possible and how? Further more is there a simple way to commit the code from the zip-archives or do I have to unzip all of them manually, move the .git-folder and commit the code for each one?

Half an answer: it's easy to set the commit date (and committer, and author and author date) with git commit :

  • --author='AU Thor <thor@host.whatever>' , --date=<date>
  • set environment variables:
    • GIT_AUTHOR_NAME : this is the AU Thor part above
    • GIT_AUTHOR_EMAIL : this is the thor@host.whatever part above
    • GIT_AUTHOR_DATE : this is the <date> part above
    • GIT_COMMITTER_NAME , GIT_COMMITTER_EMAIL , GIT_COMMITTER_DATE : these are the "committer" variants of the three AUTHOR settings.

These are documented (a bit awkwardly I think) in the manual pages for git commit , git config , and git commit-tree . See the one for git commit for date formats.

If you're unpacking things manually, there's no need to move the repo directory around, as all the git commands respect the GIT_DIR environment variable, so you can point to /some/where/bare/repo.git or whatever.

As for an automated importer, this question, Is there an opposite command to git archive for importing zip files , is not really answered and is more than two years old, so maybe not, but I don't know.

I imagine it would be pretty easy to write a Python program to read zip files and dump them into git fast-import , which would be the obvious solution here. Python already has a built-in zip-file reader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM