Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mugyu/46c6244ad3e27f5c6b13db16a0e72823 to your computer and use it in GitHub Desktop.
Save mugyu/46c6244ad3e27f5c6b13db16a0e72823 to your computer and use it in GitHub Desktop.
branchを作り忘れてmaster等にしばらくしていたコミットを正しいブランチに移動したい

branchを作り忘れてmaster等にしばらくしていたコミットを正しいブランチに移動したい

  1. 正しいブランチ(currect_branch)を作ります。その際、そのブランチの根っこになるコミットも指定します(based_commit)
$ git branch correct_branch based_commit
  1. 正しいブランチをチェックアウトします
$ git checkout correct_branch
  1. 正しいブランチに対して、今まで間違ったブランチ/masterにしていたコミットをcherry-pickを使ってコピーします
$ git cherry-pick worng_commit1
$ git cherry-pick worng_commit2
$ git cherry-pick worng_commit3
  1. 間違ったブランチ/masterにしていたコミットを削除します。
$ git checkout master
$ git reset HEAD~3 --soft

と、こんな感じでコピー&削除で移動します

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment