2
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コマンドで親ブランチ間違えた場合の対応

Posted at

github親を間違えた場合の対応です
子ブランチをたくさん生成しているときによくやってしまいます
疲れているとき、夕方集中力がキレた時に必ずやります
翌朝スッキリして対応しましょう :sun_with_face:

ブランチ作成時に親にするブランチを間違えた場合

$ git rebase --onto {本来親にしたかったブランチ} {間違って親にしてしまったブランチ名} {親を変更する作業ブランチ名}
$ git rebase --onto origin/develop work/A work/B

リベース時に本当の親じゃないブランチをリベースした場合

(1) 間違えたリベースを取り消す

$ git reflog

(2) マージ直前のHEADを見つける

66aab3fe7c (HEAD -> feature/DHCR-732_2, develop) HEAD@{164}: reset: moving to HEAD
66aab3fe7c (HEAD -> feature/DHCR-732_2, develop) HEAD@{165}: checkout: moving from feature/DHCR-732_2 to develop
5e8f8d8bc4 HEAD@{166}: reset: moving to HEAD <= コレ

(3) 見つけた場所まで一旦戻す

$git reset --hard HEAD@{166}

(4) 一度PUSHして、間違ってコミットしたものがないか確認する

git push --force-with-lease origin feature/DHCR-732_2

(5) もう一度正しい親にリベースし直す

git pull --rebase origin feature/DHCR-732

(6) 最後にPUSH

git push --force-with-lease origin feature/DHCR-732_2
2
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
2
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?