简体   繁体   中英

How to rebase your branch with master that has new schema migrations? Rails

I have a branch that has a different schema than my master. When I try to rebase with master, I get a merge conflict error with the schemas. I understand that this is happening because my schema on my branch is different than the one on my master. This is because I was working on something else in another branch and had to run migrations. I then merged that branch with my master. So now my master has a new table in the schema which the branch I am working on has no idea. So when I try to rebase with master it gives me a conflict error. Is there a way for the branch to automatically merge and take up the latest schema from the master when I rebase? I know there is a code snippet which I can put in my config file and call it in my attributes file, however, this solution does not seem to work for me since my migrations were made before I put that code in the config file.

If schema.rb (or any file for that matter) changed since you created your branch then you would have to manually merge the conflict.

Conflict happens only when file from both the branches have new changes present around same line numbers.

Doing below like mentioned in another answer would make you lose the changes done in your current branch:

git rebase -Xtheirs the_branch_name

In case of schema.rb generally the version number line throws the conflict. You should always put the higher number of two versions:

ActiveRecord::Schema.define(version: 2017081234567)

Delete the schema file, apply migrations if there are any at this stade of the rebase, dump the new rails schema and git rebase --continue . Repeat when necessary.

Since schema.rb is automatically generated after each migration, the simplest way to resolve conflict is to remove this file, run

rake db:drop db:create db:migrate

and commit the changes.

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