0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

git で branch を切り忘れた時のリカバリー方法のメモ

Posted at

よくブランチを切り忘れてPRの際に困るのでリカバリー方法をメモっておく。

例えば、 develop ブランチで作業中

  1. コードの修正がたくさん発生するも無事問題解決

  2. hotfix ブランチ作成 (これを忘れる)

  3. せっせと commit する

  4. origin に push。と思ったら 2を忘れていた事に気がつく

    リカバリー開始

  5. git の log チェック。 どこに戻すか確認しておく

  6. HEAD で hotfix の branch 作成 して local の develop の余計な Commit を削除する (リカバリー完了)

  7. hotfix を origin に push

  8. PR作成

  9. Mergeされる

  10. local の develop で pull

コマンドだと

$ git log --oneline develop
EEEEEEE hoge4 NG (HEAD -> develop)
DDDDDDD hoge3 NG
CCCCCCC hoge2 NG
BBBBBBB hoge1 (origin/develop)

$ git checkout -b hotfix-hoge234
$ git checkout develop
Your branch is ahead of 'origin/develop' by 3 commits.
$ git reset --hard HEAD~3
HEAD is now at BBBBBBB hoge1
$ git checkout hotfix-hoge
$ git push origin hotfix-hoge234

無事 GithubでPR作成。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?