Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore same database when switching branch?

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?

like image 848
Siddharth Avatar asked Dec 10 '25 22:12

Siddharth


1 Answers

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.

like image 115
user4815162342 Avatar answered Dec 12 '25 13:12

user4815162342