Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to revert to the previous submission using Git

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use Git to recover to the previous submission". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to use Git to recover to the previous submission" together!

Sometimes you want to go back to your previous commit and keep all the previous changes. You want to commit new code between the previous commit and the current HEAD.

First, create a new branch called 'revert-branch' from the commit you want to return. In this example, we want to roll back to the previous commit (assuming the current branch is 'master') and make changes on this commit.

git branch revert-branch HEAD^

Next switch to the new branch:

git checkout revert-branch

Teach a trick: soft restore from master to HEAD of new branch. Soft restore will change the state of HEAD without affecting the tree.

git reset --soft master

Now, we execute git status and we will see the changes we want to restore to the commit. I'm going to undo adding 'second.txt', but it could also be a more complex change:

$ git status # On branch revert-branch # Changes to be committed: # (use to unstage) # # deleted: second.txt #

Now let's submit this 'reversal':

git commit -m "reverted to initial state. "Thank you for your reading. The above is the content of" How to use Git to recover to the previous submission ". After studying this article, I believe everyone has a deeper understanding of how to use Git to recover to the previous submission. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report