Freezing a Git branch

后端 未结 5 730
悲哀的现实
悲哀的现实 2020-12-29 04:20

Let\'s say I have a develop branch. I create a feature branch from this to develop a feature. Once the feature is developed, it is merged back into develop. Pretty much like

相关标签:
5条回答
  • 2020-12-29 04:46

    Christopher is right, tagging will help you do this. I recommend deleting the branch name too to make it a little harder for someone to checkout the branch and make edits.

    First, merge the branch into develop

    git checkout develop
    git merge --no-ff feature_1 
    

    Then checkout the branch

    git checkout feature_1
    

    Then create a tag, with a comment.

    git tag -a -m "Freezing a feature branch that fixes.." feature_1_frozen
    

    Then delete the branch

    git checkout develop
    git branch -d feature_1
    

    After doing this, you won't be able to checkout the branch by name. Instead you'll be able to checkout the tag by name, this will put you into a detached head state which will deter changes to the code.

    Now to wrap things up and sync with origin...

    Push the update and new tag

    git push --tags origin develop
    

    Delete the remote feature branch

    git push origin :feature_1
    
    0 讨论(0)
  • 2020-12-29 04:55

    You could use something like gitolite or gerrit for access controls and permission along branches, tags and repos.

    Have a look here:

    • https://stackoverflow.com/a/10897484/462233
    • http://sitaramc.github.com/gitolite/
    0 讨论(0)
  • 2020-12-29 04:56

    I am using the "Git Bash" console to freeze the branch:

    [Solution worked Best during Oct 2018]

    Don't have Git Bash?

    Here is how to install and use the Git Bash console:

    Reference:

    https://github.com/msysgit/msysgit/releases/

    https://help.github.com/articles/set-up-git/

    How to freeze a branch

    git checkout {branch-to-keep-alive}
    git merge --no-ff {branch-to-freeze} 
    

    If git asks for a merge message, type it, then use [Esc] key then type ":wq" command to save and exit.

    You have to go to visual studio and make sure that you can build the solution successfully (with {branch-to-keep-alive}).

    git checkout {branch-to-freeze} 
    
    git tag -a -m "{your-description}" {tag-for-the-branch-to-freeze}
    

    Convention: create the tag like this: {branch-name}_frozen

    git checkout {branch-to-keep-alive}
    
    git branch -d {branch-to-freeze} 
    
    git push --tags origin {branch-to-keep-alive}
    
    git push origin :{branch-to-freeze} 
    

    How to merge a branch with master:

    git checkout {your-working-branch} 
    

    Git merge master

    Open vs and resolve merge conflicts if there is any. Always rebuild the whole things.

    git checkout master
    git merge development
    

    There won't be any conflicts now and everything is set to go.

    Git Bash Console:

    0 讨论(0)
  • 2020-12-29 05:00

    Consider git-freeze as mentioned in Git - Branch status (frozen, inactive, etc.).

    0 讨论(0)
  • 2020-12-29 05:05

    Just tag it.

    git tag -a frozen -m "Feature branch frozen here."
    git push <remote> frozen
    

    Sure, someone could come along later and push to the branch, but the tag shouldn't change unless it's forcibly overrode. You could configure your remote to reject force pushes if you're concerned about it, or even sign the tags with a GPG key to ensure authenticity.

    Getting the state of the feature branch when it was frozen is as simple as git checkout frozen. Developers can branch from this point at will using one command: git checkout -B <new_branch> frozen.

    0 讨论(0)
提交回复
热议问题