0

I haven't been using any sort of version control because of the lack of knowledge around it but just started using Git so am aware of the basic commands of git add {filename}, git commit -u {filename}, git push origin master.

As a way to track changes prior to Git, I was making multiple copies of each file I worked on e.g. the original file may have been named abc.php, the first changed could have been named abc_20130101.php, the second change, abc_20130102.php, etc.

Seeing that these were changes over a period of time and I have multiple files, what is the best approach to migrate these to a hosted service be it GitHub, BitBucket, etc.

Do I create a single repository & clone the repository? What then as I would like to avoid committing the files as a single push as they are in reality different versions? What is the best approach? How would I do it?

2 Answers 2

2

David Culp's answer is great, and I'm a bit slower at typing. I'll leave mine here anyway.

My advice would be to leave your older files as they are, and keep them as an archive. Start using Git from today, and let it track new changes to your files.

If you really want to get your development history into Git, I would do the following with a brand new repository:

  • Copy your oldest version of abc.php into the repository, making sure it's named abc.php (i.e. remove the date from the filename), and the same for any other files with the same date.
  • Do a git add .
  • Do a git commit -m "Files from 2013-01-01"
  • Repeat for each version in chronological order
  • Push to GitHub / BitBucket

Be sure to add your current versions last.

Note: If you're working by yourself, online services like GitHub / BitBucket aren't necessary. Git works fine with standalone repositories on your PC.

7
  • Thanks Gavin. I take it that with each renaming of the file, it will overwrite the previous version and this would not matter when I commit and push? I don't quite follow what you mean by Git works fine with standalone repositories on your PC.? The reason I am wanting to use a service like GitHub is to gain the experience, get into the habit of version control and ultimately share between users should the need arise. Jan 15, 2013 at 22:56
  • 2
    Yes, you overwrite the previous version. When you git commit it takes a snapshot of your files, and this snapshot is preserved forever. You can use a graphical tool like gitk to see the history, including the exact changes introduced by each new revision.
    – GavinH
    Jan 15, 2013 at 23:09
  • Git works fine with standalone repositories on your PC. - I suppose I am saying that the purpose of Git is to capture and share changes to files. If working by yourself you don't need to share changes, but the capture part is still incredibly useful. It's a huge confidence boost to know that no matter how badly you screw up a file, you can always use Git to rollback to a previous version!
    – GavinH
    Jan 15, 2013 at 23:18
  • Sorry for being such a n00b but is it common to commit and push binary files such as images, documents, etc that may be related to a project. If not how do you deal with these? Jan 15, 2013 at 23:36
  • You're doing the best thing to advance from being a n00b - asking questions! I'd definitely include any binary files that are needed to run the code, like images used on a website. As for documentation, it's whatever works for you. You might create a separate repository for documents, or use a wiki. I like to have only the code plus required files in my repositories.
    – GavinH
    Jan 16, 2013 at 0:16
0

If you want the git repository to reflect the history of the project, there would be some effort needed.

The basic steps would be to get a list of all the files that have dates (the archive files). Use this to create a list of 'revisions', then do the following:

for each revision
    recreate the project as it was in that state (renaming files so they don't have dates)
    copy the files to the repository
    add files to index
    commit files to repository

In the end you would end up with a series of commits that represented the development of the project. This could be a great deal of work, depending on how many revisions you end up with.

You might be able to script the bulk of the work, but it might end up being easier to do it manually.

This however, will result in a repository with commits at each date there was a file change. It may be possible to reduce the number of commits by combining the 'revisions' that are related to a single project feature.

3
  • Just so that I understand, the revision would be to rename each file from the day it started. E.g if the original file was called abc.php, this would be added first, committed and the pushed, I would then rename abc_20130101.php to abc.php (wouldn't this overwrite the file on my local pc), add it, commit and push, etc. Is that what you mean? Jan 15, 2013 at 22:46
  • Yes, start with the oldest, and in chunks that make sense for the project, commit them in order until the project has only the most recent of all the files. This will give you a repository with progression of commits of the changes to your project up to now.
    – David Culp
    Jan 16, 2013 at 3:47
  • Yes, the renaming will overwrite the earlier version of the same file, but since it was committed as the earlier revision you can always go back to it if you want. Once it is committed, git will not forget it.
    – David Culp
    Jan 16, 2013 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.