How to close a branch WITHOUT removing it from history in git?

后端 未结 2 1622
甜味超标
甜味超标 2021-01-30 00:10

I\'d like to make a commit and close its branch, without removing it from history.

With mercurial I\'d commit --close-branch, then up

2条回答
  •  温柔的废话
    2021-01-30 00:40

    There's no exact equivalent to closing a branch in Git, because Git branches are more lightweight than in Mercurial. Their Mercurial equivalent is more bookmarks than branches.

    If I understand correctly, closing a branch in Mercurial roughly makes it disappear from the branch list, so you can achieve the same thing by archiving it. A usual practice is to tag its tip as archive, and delete it:

    git tag archive/ 
    git branch -d 
    git checkout master
    

    The branch will be deleted, and can be retrieved later by checking out the tag, and recreating the branch:

    git checkout archive/
    git checkout -b new_branch_name
    

提交回复
热议问题