In the process of software development, Git code hosting platform is often used. There are a lot of knowledge points to know and understand about the use of Git. If you are not familiar with or skilled in using Git, you will accidentally step on a lot of holes.
Check whether the Git tool is installed on your Mac as follows:
Git code rollback means rolling back a branch of code to a previous commit version. Code rollback is also a common scenario. In this case, try not to operate frequently, and be careful to operate code rollback. When rolling back code, do a good job of backup operations. Otherwise, you will encounter irresistible losses, so try not to roll back the code until you absolutely have to. So this blog post will share Git code rollback operation, only for learning exchange use.
To clarify the difference between revert and reset:
Git revert allows you to undo a commit that you have done before or after the current commit.
Git reset reverses a commit. All changes made after this operation will be pushed back to the staging area.
There are two types of code rollback: local code rollback and remote code rollback. Local code rollback is simpler, while remote code rollback is complex and troublesome.
Rollback local code:
Git reset –hard commit_XXid: rollback to commit_XXid, delete commit after commit_XXid.
Git reset –hard HEAD~3
Remote code rollback
Remote code rollback can be complex and important, especially if you need to roll back to a COMMIT after the code has been committed and the automated deployment system has been released. The local branch needs to be rolled back to a COMMIT, the remote branch removed, and the local branch pushed again.
The specific operation is as follows:
Git checkout the_branch
2. Enter git pull and press Enter.
3. Run git branch the_branch_backup to backup the current branch code.
4. Enter git reset –hard commit_XXid and press Enter to roll back the_branch to commit_XXid.
5. Run git push origin :the_branch and press Enter to delete the_branch.
6. Run the git push origin the_branch command and press Enter to create a remote branch using the rollback local branch.
Git push origin :the_branch_backup enter git push origin :the_branch_backup and press Enter.
The above is all the content of this chapter. Welcome to pay attention to the wechat public account of Sanzhan “iOS development by Sanzhan”, and the Sina Weibo account of Sanzhan “Sanzhan 666”, welcome to pay attention to it!