When a git commit is accidentally committed to the master branch, the processing methods are: rollback the commit, create a new branch and merge, reset the master branch, delete and recreate the master branch, the branch selection method needs to consider code destructiveness, workload and history Record retention requirements.
What to do if git is submitted to master
When you accidentally submit code to the master branch, there are several Methods can be solved:
1. Roll back directly
If it is safe to undo, use the following command to roll back the commit:
<code>git revert COMMIT_HASH</code>
##2. Create a new branch and merge
<code>git checkout -b new-branch git merge master git push origin new-branch git checkout master git merge new-branch</code>
3. Reset the master branch
<code>git reset --hard COMMIT_HASH_BEFORE_UNWANTED_COMMIT</code>
4. Delete and recreate the master branch
<code>git branch -D master</code>
<code>git checkout -b master</code>
Which method to choose?
The method chosen depends on the following factors:Note:
The above is the detailed content of What should I do if git is submitted to master?. For more information, please follow other related articles on the PHP Chinese website!