How do I synchronize two branches in the same Git repository?

后端 未结 3 961
小鲜肉
小鲜肉 2021-01-31 03:03

Here\'s a common workflow hurdle I encounter often:

master is our \"stable\" branch

$ git status
# On branch master
nothing to commit (working         


        
3条回答
  •  滥情空心
    2021-01-31 03:38

    Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow. The general process can be visualized as the following:

    The example below combines git rebase with git merge to maintain a linear project history. This is a quick and easy way to ensure that your merges will be fast-forwarded.

    # Start a new feature
    git checkout -b new-feature master
    # Edit files
    git commit -a -m "Start developing a feature"
    

    In the middle of our feature, we realize there’s a security hole in our project

    # Create a hotfix branch based off of master
    git checkout -b hotfix master
    # Edit files
    git commit -a -m "Fix security hole"
    # Merge back into master
    git checkout master
    git merge hotfix
    git branch -d hotfix
    

    After merging the hotfix into master, we have a forked project history. Instead of a plain git merge, we’ll integrate the feature branch with a rebase to maintain a linear history:

    git checkout new-feature
    git rebase master
    

    This moves new-feature to the tip of master, which lets us do a standard fast-forward merge from master:

    git checkout master
    git merge new-feature
    

    Taken from Atlassian Git Rebase Tutorial

提交回复
热议问题