Problem 1.

The company has two main public branches on GitLab, namely the public warehouse Master, which is the main library for pushing code online; The other is the common repository Bugfix branch, which is used to hotfix minor bugs. The two branches cannot be merged, resulting in a chaotic master version.

Some time ago, I needed to warm up a small function, which was developed based on the Bugfix branch and submitted to the Bugfix branch. After that, I continued to develop directly on this branch and made major changes. Yesterday, I needed to submit my finished part to the master branch of the public repository. However, we found that the commit of the previous several bugfixes was brought to the master branch of the common repository as shown in the following figure:



cherry-pick

Git cherry-pick can select one or more commits on a branchCopy the code

2. Solve

git log| less view of the current branchlogGit checkout master git fetch --all $git rebase us/master $git status $git push $git status $gitlog |less
$ git branch
$ git checkout oldBranch 
$ git logView the old branchlog$git checkout master $git status $git checkout -b newBranch $git cherry-pick $git status $git = $git = $git = $gitlog$git status $git push -u origin newBranch $git statusCopy the code

3. Summary

Git is the most important tool for corporate collaboration.