Git reset and delete branch not reverting back properly

I created a new branch called user-microposts. I proceeded to mess something up on creating a model. I tried going back to the last commit using:

git reset --hard cb166caa1c70004f77eed6229168b06ad249a4ba

which gave back:

HEAD is now at cb166ca Eliminate an unnecessary assignment

So I tried redoing the Migrate, which gave me this error:

SQLite3::SQLException: table "microposts" already exists: CREATE TABLE "microposts"
....

I was surprised because I thought if I went back to the previous commit, it would be like nothing happened.

So I reverted back to master branch and deleted the branch in which I made any changes.

I then created a new branch, and tried to create another model and run rake db:migrate. Again I got the same error

SQLite3::SQLException: table "microposts" already exists: CREATE TABLE "microposts"
....

I recently tried to manually delete any file with microposts in it. Again with no such luck.

I keep getting the same error. I thought the purpose of both the git branch and/or git reset would prevent this scenario, so I am very confused. Any help would be appreciated


It would be unusual for your database to be under source control. Thus, if you revert your source you will likely have inconsistencies between the database and the source. The solution has a few options:

  • delete the database and recreate it
  • rollback the database to match the source
  • For both of the above you'd use the typical 'rake db' type commands.

    链接地址: http://www.djcxy.com/p/18918.html

    上一篇: Git远程钩子没有承诺

    下一篇: Git重置并删除分支不能正常恢复