简体   繁体   中英

How do I migrate multiple versions of code across using Git?

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 eg 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?

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 (ie 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.

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.

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