Get the App
SLTechnology News&Howtos  ›  Development  › 

How to revert to the previous submission using Git

Shulou Source: shulou.com Published: 2022-06-02 14:12:36 09月10日 Update

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!

Tags: Branches changes learning code content complexity next between examples that is ideas situations I want articles more sometimes status knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Microsoft Shulou Information vpn