Git (pronounced /gɪt/) is an open source distributed version control system that can handle project version management from the very small to the very large efficiently and quickly. Git is an open source version control software developed by Linux author Linus Torvalds to help manage Linux kernel development.

The biggest difference between distributed and centralized is that developers can commit to a local repository. Each developer can copy a complete Git repository on their own computer with git Clone.

If you are struggling with how to use and manage Git configuration, or want to explore a more efficient way to manage your code version, then I recommend the Power Node Git tutorial to help you quickly master this skill. In this course, Will be a complete description of the development history of GIT tools, the use of GIT tools, branch management, remote repository, etc.

Online viewing link:

I.bjpowernode.com/courses/151…

Information, source code download:

www.bjpowernode.com/javavideo/1…

I. Problem description

In the context of github, some of the most common things you can do are to undo a submission and revert it back to what it was before it was submitted. There are two ways to do this: reset and revert.

Second, background knowledge

Every commit with Git is automatically strung into a timeline. This timeline is called a branch. If there is no new branch, then there is only one timeline, i.e. only one branch. In Git, this branch is called the master branch. There is a HEAD pointer to the current branch (if there is only one branch, it points to the master, which points to the latest commit). Each version has its own version information, such as unique version number, version name, and so on.

As shown below, suppose there is only one branch:

Third, solutions

Git reset

Git reset changes the location of the HEAD to a previous version, as shown in the following figure.

Application scenario: This method can be used if you want to revert to a previously committed version and we don’t want any later versions.

Specific operation:

  1. View the version number:

You can run the git log command to check:

You can also check it out on Github:

2. Run the “git reset –hard target version” command to roll back the version:

Then run the Git log command to check the version information. The local HEAD already points to the previous version:

Git push -f git push -f git push -f git push -f git push

Git push-f: git push-f: git push-f: git push-f

The HEAD of the remote library is already pointing to the target version:

The rollback succeeded!

Git Revert

Git revert is used to “reverse” a version to undo changes made to that version. For example, we commit three releases (version 1, version 2, and version 3) and suddenly discover that version 2 doesn’t work (e.g. If you want to undo version 2 without affecting a commit to undo version 3, you can use git revert to reverse version 2 and create a new version 4 that retains version 3 but undoes version 2. As shown below:

Application scenario: If we want to undo a previous version, but we want to keep the later version of the target version and record the entire version change process, we can use this method.

For example, there are three files in the library: read.md, text.txt, and text2.txt.

  1. View the version number:

You can view it through the command line (enter git log) : as shown in the figure, the latest two versions are respectively called “Add text.txt” (text.txt) and “Add Text2.txt” (text2.txt). TXT file is not needed at this point, which means that we do not want to “add text. TXT” version of the operation, that can be done by “add text. TXT” version.

You can also view the version number on github’s graphical interface:

Git commit -m git commit -m git commit -m

Git revert -n version number The following command is used to reverse the version 8B89621:

git revert -n 8b89621019c9adc6fc4d242cd41daeb13aeb9861

Note: Conflicts may occur here, so you need to manually modify the conflicting files. And git add the filename.

Git commit -m

git commit -m "revert add text.txt"

In this case, you can use git log to view the local version information. It can be seen that a new version is generated, which is reversed to add text. TXT but retains the add text2. TXT version:

3. Use “Git push” to push remote library:

git push

View the remote library version information displayed on Github:

If you look at the repository file, there are two remaining: read.md and text2.txt

Reverse success!