Explain idea git branch backoff specified historical version

Time:2020-10-21

scene

When I submitted this modification to the local and remote branches, I found that there were still some changes missing in this submission, or this modification was totally wrong, but I also pushed it to the remote repository. How to go back?

problem

How can the content that has been submitted to the repository (local and remote repository) be rolled back to the original specified version with idea?

method

There are two methods: 1. Reverse operation; 2. Using the reset head pointer of idea

influence

The revert operation of method 1 will be appended to the commit log as a new commit record, thus retaining the original commit record. (recommended)

The reset head pointer of method 2 will discard the original submission record and force the head pointer to the specified version.

Experimental environment

The picture above shows the experimental environment. This experiment only operated Readme.md Documents. When initializing, the “git” branch used by the master and demo_ Demo “refers to version 1:” version 1: edit for the first time “text content. The current operation branch is GIT_ demo。

explain

The experimental environment may not be completely consistent with your situation, but the general idea is the same. If you encounter a conflict in the process of solving the problem, you can solve it.

Method 1: reverse operation

After modifying the content based on version 1 and submitting it to the local or remote warehouse, it is found that the submitted content is not what I want, or is completely wrong, so version 1 needs to be rolled back.

step

Right click the historical version you want to roll back and select revert (see figure below)

The conflict dialog box will pop up. Double click the conflict file to resolve the conflict. (see figure below)

In the resolve conflict dialog box, determine the final version file. (see figure below)

Re submit to local warehouse (see figure below)

Push

Synchronous remote warehouse (see figure below)

The advantage of this fallback is that if you regret the “fallback” operation, you can also go back to the previous version. Because the history also keeps the submission record.

Method 2: reset head pointer

After modifying the content based on version 1 and submitting it to the local or remote warehouse, it is found that the submitted content is not what I want, or is completely wrong, so version 1 needs to be rolled back.

Step right click the historical version you want to roll back and select “reset current branch to here” (see figure below)

In the pop-up git reset parameter type selection box, select hard (see the figure below), and reset

The local warehouse is back to version 1, and the remote warehouse needs to be synchronized to perform the push operation.

push

After that, you will be prompted to reject. Open terminal, in the project directory, enter git push – F to force synchronization of remote warehouse.

After synchronization, it will be found that git logs have lost the commit after version 1.

summary

  • The revert operation is actually a rollback operation. By default, it is back to the latest submission point or to the specified submission point, as demonstrated in this experiment.
  • The operation of revert is actually to set the head pointer.
  • In fact, we recommend the revert operation. After all, we can regret it. Method 2 git push – f mandatory synchronization is not recommended and may cause problems in a team collaboration environment.
  • In method 2, the GIT reset parameter is selected as hard, which is suitable for scenarios where I just want to go back to the specified version of the text. Content in the workspace can be discarded, version 2 completely abandoned. You can also choose mixed. Mixed is used to keep the text content in the current workspace when setting the head pointer. This is convenient to modify directly, which is suitable for the situation that the submitted content is wrong and you just want to correct it back. (see the figure below for comparison)

In the process of fallback, your situation may not be as simple as this experiment, that is to say, there will be conflicts. Then just resolve the conflict.

ending

In addition to the hard and mixed options, other fallback options can be demonstrated here: git reset mode demo

There may be many ways to go back, and this experiment is one-sided. It is inevitable that there are some mistakes and omissions. Please don’t be stingy with your talents. Please correct them more

This article on the detailed explanation of idea git branch fallback specified historical version of the article introduced here, more about the idea git branch backoff specified historical version content, please search the previous articles of developpaer or continue to browse the related articles below, I hope you can support developeppaer more in the future!