内容
db/schema.rb
カラム追加したブランチをリベースしようとしたところで発生
<<<<<<< HEAD ActiveRecord::Schema.define(version: 20200513032325) do ======= ActiveRecord::Schema.define(version: 20200506032438) do >>>>>>> ブランチ名
最新のversionを選択した 次migrationする人がいれば、エラーが起きないように
で、修正
リベース続行
$ git rebase --continue db/schema.rb: needs merge You must edit all merge conflicts and then mark them as resolved using git add
修正したはずが、リベース が走らない。、 (エラー内容をちゃんと読んで、git add 使えば解決は早かったはず)
走らんやんけ、と思って、
[git] rebaseが完了できない現象("--continue"を飛ばしてしまったため)の解消手順 - Qiita この記事参考に--quitというオプションで、rebaseを中断しつつ、HEADは維持する形で進めてしまった
$ git rebase --quit
ブランチ確認
$ git branch * (HEAD detached from refs/heads/ブランチ)
実はHEADの扱い方を知らない、
detached HEADはこの記事を参考にしました
detached HEAD から脱出する方法を git の内部構造から探る - Qiita
ステータス確認
$ git status HEAD detached from refs/heads/ブランチ Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: app/controllers/yyy/xxx_controller.rb modified: app/views/yyy/xxx/index.html.slim new file: db/migrate/20200506031358_zzz.rb modified: db/seeds.rb modified: spec/requests/yyy/xxx/zzz_spec.rb Unmerged paths: (use "git restore --staged <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: db/schema.rb
さっきも git add してよって書いてあったけ?とようやく気づく
db/schema.rb が git add されていないようです。
なので、してあげましょう
$ git add .
もう一度ステータス確認
$ git status HEAD detached from refs/heads/ブランチ Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: app/controllers/yyy/xxx_controller.rb modified: app/views/yyy/xxx/index.html.slim new file: db/migrate/20200506031358_zzz.rb modified: db/schema.rb modified: db/seeds.rb modified: spec/requests/yyy/xxx/zzz_spec.rb
よしよし、できてきた。
新しいブランチに移すのにgit stashを使った
参考 間違えてmasterで作業してしまった修正内容を別のブランチに移動させる方法 | ハックノート
修正内容を別の場所に一時保管します
$ git stash Saved working directory and index state WIP on (no branch): 2824bed2 最新のコミットメッセージ
ここでgit statusを行うと修正内容はなくなっているはずです
今回は新しいブランチに切り替える
$ git checkout -b 新ブランチ Switched to a new branch '新ブランチ'
さっき一時保管されていた内容を切り替えたブランチに適用
$ git stash apply On branch 新ブランチ Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: db/migrate/20200506031358_zzz.rb Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: app/controllers/yyy/xxx_controller.rb modified: app/views/yyy/xxx/index.html.slim modified: db/schema.rb modified: db/seeds.rb modified: spec/requests/yyy/xxx/zzz_spec.rb
やっと戻って来れました。次回はすっきり対処したい