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?

Git 切るブランチを間違えた時にあとから変更する方法メモ

Last updated at Posted at 2024-06-06

はじめに

developブランチから新しいブランチを作成して、あとからmasterに直接マージするものだったと気付いて、masterから切ったことにしたくなりました。
GithubCopilotに教えてもらったコマンドがいい感じに動いたのでそのメモです。

手順

developから切ったブランチをfeature,これをmasterブランチから切ったことにしたい体で手順を書いていきます。

ブランチの根本を入れ替えたいブランチにチェックアウト

git checkout feature

リベース

git fetch -p
git rebase --onto origin/master origin/develop

指定commitIdから先をmasterのブランチに付け替える場合はこの様になります。
(^をつけることで指定のcommitIdも含めます)

git rebase --onto origin/master [指定commitId]^

リベース前にpush済みの場合はforce push

git push origin feature -f
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?