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?

mainブランチで行ったコミットを別ブランチで行った事にしたい

Last updated at Posted at 2025-06-15

次のAscii Art(以下では図と記載)はinitコミットに変更を加えnew featコミットを行った直後の状態を示している。HEADはmainブランチの先頭を指している。new featをテストしていると不具合が発生するのでng tagをつけて、更にnew featをmain branchからng branchに移動する手順を述べる。

注釈: 下記の図でinit, new feat, new feat2はコミットを表す。実際にはコミットハッシュである。ng, mainはbranch。tag ngは図には表していない。tag名, branch名は重複して同じ名前を付与可。

init -> new feat
        |
        HEAD -> main

最終の状態

init -> new feat
|       |
|       ng
HEAD -> main
  1. new featコミットにtag ngを付与

    $(main) git tag ng
    
  2. HEADをinitへ移動

    $(main) git go @~ # goはreset --hardのgit alias
    
  3. ng branch作成、移動。作成する際にはtag名と重複可能。

    $(main) git br ng; git sw ng # br, swはbranch, switchのgit alias
    
  4. ng branchでng tagのコミットをmerge

    $(ng) git merge ng # ngはtag
    
  5. main branchへswitch、不要となったng tag削除

    $(ng) git sw main
    $(main) git tag -d ng
    

この状態でworking treeを編集してnew feat2コミットを作成したなら次の状態になる

init -> new feat2
      \   |
  new feat|       
      |   HEAD -> main
      ng
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?