Git revocation submitted

Git in several states

Unmodified
       Original content
Modified ↓   
       Workspace
It has been staging ↓ git add
       storage cache
Submitted ↓ git commit
       Local Warehouse
Pushed ↓ git push
       Remote repository

 

Note : All the following command for each code segment is independent of each other, in order to solve a problem, do not use multiple code segments. All commands after I test, because the test environment is simple Git repository without too much data, errors may occur in complex environments back. Please direct comments such as problem area pointed out. Carefully analyze usage, and I have nothing to lose data.

Modified not scratch

Has modified the file, it has not been carried out git add.
Content that is the work area do not want it.

Recovery Methods

Use any of the following command

git checkout .
git checkout -- <FILENAME>
git reset --hard

 

Staging has not submitted

Have been carried out git add, it has not been carried out git commit
that is the staging area of the unwanted content

Recovery Methods

Use any of the following command

git reset
git checkout .
git reset --hard
git reset HEAD
git reset HEAD -- <FILENAME>

 

Submitted not push

Have been carried out git commit, has not been carried outgit push

Recovery Methods

Using remote warehouse covering local warehouse

git reset --hard origin/master

 

Pushed

We have beengit push

Recovery Methods

Roll back the local repository, a remote repository forced to push coverage

git reset --hard HEAD^
git push -f

 

Other situations

All submitted after dropping a node

I.e. HEAD pointer to the node

git reset --hard <COMMITID>

Guess you like

Origin www.cnblogs.com/T8888/p/12124088.html