IDEA Git operation (two) HEAD separation state, operators ^ and ~, use reset and revert to cancel the submission

Description

This tutorial is   carried out in the order of git online exercises . The command operations of the online test are implemented in IDEA, and the development tools are used to implement all the operations in the online exercises.

You can combine  git online exercises  to learn this tutorial, first learn git commands online, and then implement the same operations in IDEA.



 

HEAD detached state



 

Ready to submit structure




Switch to master and reset master to the second commit

Delete bugFix

New bugFix branch

Switch to master and make a commit

Switch to bugFix and make a submission

Submit another bugFix

The above submission history is compared to   the structure diagram of learngitbranching.js.org

HEAD detached state




Use the hash value to switch to the last commit

At this time, HEAD and bufFix are separated

The above submission history is compared to   the structure diagram of learngitbranching.js.org

Operator ^




Switch to master

Now, HEAD is in the master position

The above submission history is compared to   the structure diagram of learngitbranching.js.org

Use the operator "^" to switch to c3

git checkout bugFix^

# In the dos command, ^ is a special symbol that needs double quotes, so it should be written as:
git checkout "bugFix^"
 

Run commands in Terminal

Now, HEAD is in the last commit position of bugFix

The above submission history is compared to   the structure diagram of learngitbranching.js.org

Operator ~ and forced move branch position



 

Ready to submit structure




Switch to master

Submit once

Switch to bugFix and submit again

HEAD moves to the previous commit of master

git checkout "master^"
 

bugFix forced to move to bugFix^
The position of the branch can be forced to move through the -f parameter

git branch -f bugFix "bugFix^"
 

There is now a hidden commit on the bugFix branch: "Add Print-2", take a look at its hash value

go reflog
 

The above submission history is compared to   the structure diagram of learngitbranching.js.org

Operator ~ and forced move branch position

The master is forced to move to the hidden commit (the hash value seen in the previous step)

git branch -f master b6c4
 

bugFix forced to move to the initial submission

git branch -f bugFix bugFix~3
 

Switch to the second submission

git checkout "HEAD^"
 

The above submission history is compared to   the structure diagram of learngitbranching.js.org

reset and revert



 

Ready to submit structure




reset master to the second commit, delete the bugFix branch

Create a pushed branch and submit it once

Switch to master again, create a new local branch and perform a commit

The above submission history is compared to   the structure diagram of learngitbranching.js.org

Use reset to cancel submission




Reset the local branch to the previous commit

git reset local^

# Dos should add double quotes
git reset "local^"
 

local submission has been revoked

Use revert to cancel the submission




Switch to the pushed branch first, and then use revert to undo the changes of the pushed branch

revert will take one step forward on the current branch and generate new commits

The newly generated submission is the same as the submission of "Add Print 2", which is equivalent to canceling "Add Print 3"

The above submission history is compared to   the structure diagram of learngitbranching.js.org

 

Guess you like

Origin blog.csdn.net/abu1216/article/details/111003024