2
2

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 5 years have passed since last update.

gitでブランチ作り忘れてmasterにcommitしちゃったときの対処

Posted at

やらかすパターン

masterのままで、勢いあまってコミットまでやっちまってることは稀によくある。
pushしようとした瞬間気づく。ここmasterや……。

分身して出戻りすればいいじゃない

  1. 同じコミットを参照する新しいHEADを参照するブランチを作る
  2. masterの参照位置をorigin/masterまで移動する
  3. 何事もなかったかのようにブランチで作業を続行する
git checkout -b NEW_BRANCH
git checkout master
git reset --hard origin/master
git checkout NEW_BRANCH
2
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?