Scene
When I submitted this modification to the local and remote branches, I found that I had less modification content in this submission, or that this modification was completely wrong, but I also pushed to the remote repository. How to fall back?
question
How to fall back to the original specified version using IDEA?
method
There are two methods: 1. Revert operation 2. Use IDEAResetHead pointer
Influence
The Revert operation of Method 1 will be treated as a new commit record and will be appended to the commit log, thus retaining the original commit record. (recommend)
The Reset Head pointer of Method 2 will discard the original commit record and make the Head pointer force it to point to the specified version.
Experimental environment
The above picture shows the experimental environment. This experiment only operatesReadme.md file. During initialization, both the master and the branch "git_demo" used by the demo point to the text content of version 1: "version 1: first editing". The current operation branch is git_demo.
illustrate
The experimental environment may not be exactly consistent with your situation, but the general idea is the same. If you encounter conflicts during the resolution of the problem, just resolve it.
Method 1: Revert operation
When you modify the content based on version 1 and submit it to the local and remote repository, you find that the submitted content is not what I want, or it is completely wrong, and you need to fall back to version 1.
step
Right-click the version you want to fall back and select "Revert" (see the image below)
At this time, the conflict dialog box pops up and double-click the conflict file to resolve the conflict. (See the picture below)
In the Resolve Conflict dialog box, decide on the final version file. (See the picture below)
Resubmit to the local repository (see the picture below)
Push
Synchronize remote repository (see the picture below)
The advantage of this fallback is that if you regret the "fallback" operation, you can also fall back to the version before it has not fallback. Because history also keeps submission records.
Method 2: Reset Head Pointer
When you modify the content based on version 1 and submit it to the local and remote repository, you find that the submitted content is not what I want, or it is completely wrong, and you need to fall back to version 1.
Step Right-click the version you want to fallback and select "Reset Current Branch to Here" (see the picture below)
Pop-upgitreset parameter type selection box, select Hard (see the figure below), and Reset
The local repository falls back to version 1, and needs to synchronize the remote repository and perform push operations.
push
After that, Push is prompted to refuse. OpenTerminal, in this project directory, enter git push -f to force synchronization of the remote repository.
After synchronization, you will find that the git log has lost the commits after version 1.
Summarize
The Revert operation is actually a fallback operation. By default, it is to fall back to the most recent commit point, or it can fall back to the specified commit point, just like the demonstration in this experiment.
Revert's operation is actually also setting the Head pointer.
Actually, I recommend the Revert operation, after all, I can regret it. In Method 2, git push -f forced synchronization operation is not recommended, and may cause problems in a team collaboration environment.
In Method 2, selecting the git reset parameter is hard, this parameter is suitable for the scenario where I just want to fall back to the specified version of text. The content in the workspace can be abandoned, and version 2 can be abandoned completely. Actually, you can also choose Mixed. Mixed is used to retain the text content in the current workspace when setting the head pointer. This is convenient and direct modification, suitable for the submission of the content is incorrect, and you just want to correct it back. (See the picture below for comparison)
During the fallback process, your situation may not be as simple as this experiment, which means there will be conflict situations. Then you just need to resolve the conflict.
Ending
In addition to the Hard and Mixed options, the effect demonstration of other fallback options can be accessed here: Git Reset Mode Demo
There may be many ways to back the version, and this experiment is also one-sided. There are inevitably some mistakes and omissions. Please don’t be stingy with your own talents. Please ask the teachers to correct them more.
This is the article about detailed explanation of the specified historical version of IDEA git branch rollback. For more related contents of IDEA git branch rollback, please search for previous articles or continue browsing the related articles below. I hope you will support it in the future!