In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Git version of the regression method related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone will have a harvest after reading this Git version of the regression method article, let's take a look at it.
git reset
Suppose our system now has the following commits:
where A and B are normal submissions and C and D are false submissions. Now, we want to roll back C and D. In this case, the HEAD pointer points to D commit (5lk 4er). We can do this by simply moving the HEAD pointer to B commit (a0fvf8).
As long as you have a git foundation, you will definitely think of the git reset command. The complete command is as follows:
git reset --hard a0fvf8
After the command runs, the HEAD pointer will move to B submit, as shown below:
At this point, the HEAD pointer to the remote repository remains unchanged, still on D commit. So, if you use the git push command directly, you won't be able to push changes to the remote repository. At this point, you can only force submissions to remote repositories using the-f option:
git push -f
The obvious downside of rolling back code in this way is that it moves the HEAD pointer back and loses subsequent commit information. In the future, if you suddenly discover how wonderful C and D are, they will have long disappeared in the long river of history.
Moreover, some companies (such as the good ones) explicitly prohibit the use of the git reset command to rollback code for the same reason. So, we need to find a command that both rolls back the code and saves the wrong commit. The git revert command comes in handy.
git revert
git revert creates a new version by doing the reverse, which has the same content as the target version to which we want to revert, but the HEAD pointer points to the newly generated version, not the target version.
Using the git revert command to implement the above example, we can do this: revert D first, then revert C (if there are multiple commits to revert, you need to revert from new to old):
git revert 5lk4ergit revert 76sdeb
Two new commits are generated: D 'and C' as shown below:
There are only two commits that need to be reverted, and we can revert one by one. But what if there are dozens? Backtracking one by one would be inefficient and error-prone. We can use the following methods for batch rollback:
git revert OLDER_COMMIT^.. NEWER_COMMIT
At this time, the wrong submissions C and D are still retained, and there is a basis for future pan shaking. Moreover, if you do this, the HEAD pointer is moved backwards and can be pushed directly to the remote repository using the git push command. This is exactly what businesses encourage.
Let's take a harder example.
Suppose there are three commits, but unfortunately, the wrong commit is right in the middle. The following diagram shows:
At this point, directly using the git reset command to reset the HEAD pointer to A commit is obviously not acceptable, because C commit is correct and needs to be preserved. The requirement to roll back the B commit is fulfilled by rolling back both the C commit and the B commit, and then regenerating the C commit with the cherry-pick command into a new commit C". The complete process is as follows:
From the above comparison, we can see that the biggest difference between git reset and git revert is that git reset loses the subsequent commit, while git revert re-creates a new commit by doing the reverse, while retaining the original commit. In the enterprise, you should try to use the git revert command as much as possible. If you can, you should not use the git reset command as much as possible.
The content of this article on "Git version rollback method" is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "Git version rollback method." If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.