3

I have a question regarding the version control and database. My problem is that I have a branch 'b1' that is stable, now I have created another branch 'b2' and worked for couple of days. Now after few days I am to switching to my previous 'b1' branch.

But my problem is Mysql database still having same database as 'b2' branch. But I want to have the same database when I left with branch 'b1', only those table and those data.

How to achieve this?

Zombo
  • 1
  • 62
  • 391
  • 407
Siddharth
  • 833
  • 6
  • 12
  • 25
  • 2
    Was your database (or, more likely, your database dump) under version control? Did you make backups? If you answer no to either of those questions then you are very likely out of luck. – sosborn Mar 02 '13 at 07:32
  • Yes, I have taken backups for that version. But all That I want is to when I'm switching branches, it should automatically restore database like git repository. Don't know wheather I have to modify my git commands. – Siddharth Mar 02 '13 at 07:53

2 Answers2

1

To do this automatically, you would need to put all database files under version control. Additionally, since the database server doesn't expect those files to change without its knowledge, you would need to restart the server when switching branches. Of course, if the database is being written to, you would also need to commit the changes (in git) after every modification.

If you need this kind of functionality, consider switching to a server-less database that is more suited for this kind of operation. For example, SQLite has no separate server process and holds all database contents in a single file.

user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • [This previous answer](http://stackoverflow.com/questions/846659/how-can-i-put-a-database-under-git-version-control) will also help you out to really understand what the issue is with databases and version control. – sosborn Mar 02 '13 at 17:17
1

Assuming you're using development snapshot data you could just have two different databases one with the data that works with b1 and the other that works with branch b2.

In your branched code modify the database reference so you're referencing the new database there.

James C
  • 14,047
  • 1
  • 34
  • 43