Explain the idea git reset option in detail

Time:2020-10-22

1. Objectives

Demonstrate the effect of GIT reset options in the figure below.

2. Git reset operation instructions

The figure shows:

his will reset the current branch head to the selected commit, and update the working tree and the index accoding to the seleted mode.

intend:
This action resets the current branch pointer to the selected commit point, updates the record point and updates the index status based on the selected option.

This means that the action affects two things: the submitted record and the state of the file in the current workspace.

3. Environmental description

To simplify the demonstration, the master branch is used this time. The initial status of the master branch is shown in the following figure:

The effect demonstration of each option in this article is carried out under the requirement of “back to version 1”.

Pop up option box

4. Effect description of each option

4.1 Soft

Soft option: all changes after the selected fallback point will be retained and tracked by GIT. This means that they can be viewed in the local changes panel of version control.

create a new file demo.txt And index. bring demo.txt Files can be tracked by GIT.

At this point, we are based on the workspace of version 2 demo.txt At this point, we want to go back to version 1 and use soft mode. The results of the regression are as follows:

4.2 Mixed

Mixed mode: all changes after the selected fallback point are retained but not tracked by GIT.

create a new file demo.txt And index. bring demo.txt Files can be tracked by GIT.

At this point, we are based on the workspace of version 2 demo.txt At this point, we want to go back to version 1 and back in mixed mode. The results are as follows:

4.3 Hard

Hard mode: all changes after the selected fallback point are discarded. (including tracked and submitted documents)

Add text on the basis of version 2 to form uncommitted version 3

Back to version 1 in hard mode.

4.4 Keep

Keep mode: all committed changes after the selected fallback point are discarded. But the local changes will be completely saved.

Add text on the basis of version 2 to form uncommitted version 3

The effect of using keep mode to fallback to version 1 is as follows:

Note: the GIT reset problem dialog box appears in the above figure because the keep mode will keep the contents modified in the workspace. Therefore, after backing back to the specified submission point, idea needs to deal with the contents modified in the workspace, so the user is asked whether it is necessary to keep the contents. If you don’t have to keep it, you can have hard reset; if necessary, you usually need to resolve the conflict in the next step.

The effect of hard reset is shown in 4.3. After clicking smart reset, the effect is as follows:

Yes, stash and unstash are automatic.

Note: users can also manually stash and unstash operations, similar to stack pressing and pop stack operations. This mechanism can help us to have a solution in the embarrassing situation that “we don’t want to submit the modified one for the time being, but now we must start to develop another set of things on the previous version without modification”. This concept is like how to save the interrupt site after the CPU is interrupted. After processing other tasks, it can restore the scene at that time. Here is also: how to save the current uncommitted content after the current development version is interrupted, and then restore it after other things have been developed.

5. Summary

Soft: all changes made after the commit point is selected are staged (which means you can go to the local changes tab of the version control window (ALT + 9) so that you can view them and commit later if necessary).

Mixed: changes made after the selected commit are retained, but not staged for commit.

Hard: all changes made after the selected commit are discarded (staged and committed).

Keep: committed changes made after the selected commit are discarded, but local changes remain unchanged.

If you need to use idea for version fallback, you can access the idea git branch to rollback the specified historical version

This article on the detailed explanation of the idea git reset option description will be introduced here. For more related idea git reset option content, please search the previous articles of developeppaer or continue to browse the related articles below. I hope you can support developpaer more in the future!

Recommended Today

PHP 12th week function learning record

sha1() effect sha1()Function to evaluate the value of a stringSHA-1Hash. usage sha1(string,raw) case <?php $str = “Hello”; echo sha1($str); ?> result f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 sha1_file() effect sha1_file()Function calculation fileSHA-1Hash. usage sha1_file(file,raw) case <?php $filename = “test.txt”; $sha1file = sha1_file($filename); echo $sha1file; ?> result aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d similar_text() effect similar_text()Function to calculate the similarity between two strings. usage similar_text(string1,string2,percent) case […]