Search code examples
gitgithubversion-controlsnapshotrevision-history

How to create a git repository with its own history from snapshots?


The situation

  • I have a project I have been working on from back before I used version control systems (VCS).
  • I used to copy and paste the entire project as I made progress in order to save "snapshots" of my work in order to have a history to look back upon.
  • Since then, I have switched over to using version control systems for my other, more recent projects, as using the "copy, paste - snapshot" approach has become a massive waste of space, and has poor utility.

Goal

I would like to create a repository that correctly represents the stages of development.

My plan

  • Create a new repository and initialize it using the oldest snapshot folder.
  • Make commits by replacing the old folder with the next more recent snapshot folder, while keeping the hidden .git folder.
  • Repeat step 2 until git is updated with the most recent snapshot, i.e. the current working directory.

Question

  • Is this a viable way to accomplish this?
  • If yes, are there any improvements I could make to this approach?
  • If no, how should I do this?

Additional Information

I am willing to use GitHub's client, Git Bash, git shell, or anything really in order to do this. I am most comfortable with the GitHub client software, but am more than happy to learn other methods.

Extended Question

If I wanted correct dates, should I change them via environment variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE (which I don't know how to do), or is it not worth the hassle? Or would the file's metadata (properties) maintain this information when committing it? This would be for aesthetic reasons mostly (as far as I can think of), as I'd be committing the files chronologically anyways.

EDIT: Result

I used the steps listed in "My plan" and it worked out perfectly.


Solution

  • IMHO, your planned method is fine.

    When saying replacing the old folder with the next more recent snapshot folder, you need to take care that you're really replacing: delete everything in the repo except the .git folder and then add the content of the next snapshot folder.

    If you don't do it that way, you won't notice deletions between the snapshots correctly.

    I would not play around with GIT_AUTHOR_DATE and GIT_COMMITTER_DATE unless you have a relation of a certain commit with a certain date (e.g. you need to know which version of your website was live on 01/01/2015 or something like that).

    Even if you need to connect a certain commit to a certain state, I'd go for a tag in that case (e.g. git tag website_01_01_2015).