Home>

We are developing web applications using ruby ​​on rails.

Suppose I want to derive a topic branch from the master branch in git and develop in the topic branch
Suppose you created a user model in the topic branch

rails g model User
rails db: migrate

If i were working on the topic branch at that time and you don't want to work on the topic branch

git stash
git checkout master
git stash drop


Suppose
Even in such a case, if ralis db: migrate in the topic branch, it will be reflected in the database, and I think that it will affect the master branch as well.
(If i were working with vscode, even if you return to the master branch, the user migration file remains in the working directory)

Is there a way to avoid this, no matter what I do in the topic branch, it has no effect when I return to the master branch? Also, if there is something wrong with your own way (git stash, etc.), please teach me.

  • Answer # 1

    Is there a way to avoid this, no matter what I do in the topic branch, it has no effect when I return to the master branch?

    I don't think there is. So I think you have to adjust it yourself (humans use their heads carefully).

    In this case,git stashBefore you do
    Roll back the migration file applied in the topic branch (rails db: rollback)
    That would be reasonable. Of course, for that, the migration filedownYou have to implement the method properly.

    Also, when you roll back,usersPlease note that the table will disappear (later)git checkout topicHowever, the DB data does not come back).

    Also, if there is something wrong with your own way (git stash, etc.), please teach me.

    In this case, I don't think it's wrong (I can't say it unconditionally because I should use different commands depending on the purpose and the state of the working directory ...). The remaining migration files are annoying, so delete them (if you don't plan to use them anymore).reset --hardOrclean -fPlease also study.