This article uses the gitHub client to compare the differences

git reset

If the most recently submitted code has been pushed to the remote end and you want to delete the submitted code from the remote end and erase the record

Git reset SHA –hard

Attention!! SHA refers to the EARLIEST submitted SHA as shown

In GUI input git reset b8a9905399e3dca639b3383cdf8e1578885ad 926 – hard to submit the latest of the code will be erased 【 if there N times before submit, N then this N times submitted will be erased 】

Now the remote will tell you to pull the branch because you erased the local last commit and it will tell you to pull the remote branch and if you click on the Fetch Origin the code will go back to the last commit

Get back to business

If you type Git push Origin directly into the GUI, Git will prompt you that the update has been rejected because the latest commit from your current branch is behind its corresponding remote branch.

Well, my branch does lag behind the remote Develop branch. I need to — force

Git push origin –force

The code then reverts back to the original submission

– the role of hard

Git reset SHA () {git reset SHA ()

If hard is added, all code and records submitted will be erased

For example, do not add –hard

Summary If code has been pushed to the remote side want to erase the record

Git reset SHA –hard

Git push origin git push origin

Git revert differs from Git Reset

Git revert (” Commit “); git revert (” commit “)

Git reset — delete git reset — delete git reset — delete git reset — delete git reset — delete

Note: Use revert with caution!!

Get Revert can affect other people’s code in collaborative development

For example

Scenario: There are now two branches: the “dev” branch and the “from-dev-22” branch to merge dev code into the from-dev-22 branch

And now, for some reason, I don’t want to do that,

To rollback back, you used the revert rollback code on dev

The commit and rollback records that merged dev into from-dev-22 should be on the FROm-dev-22 branch. This is now on the dev branch (and the dev code has been changed). This is one of the things I don’t understand (I think the root cause is git-revert). If another of your colleagues changes code on Dev at this point, their code will be erased entirely (I don’t know why). What if this happens

**revert this commit **

Note that since there have been multiple submissions, this revert will appear in your local record, and you need to see if there are any conflicts that need to be resolved before you commit

When can YOU revert?

You can use it on your own branch, and revert keeps a record of changes so it doesn’t bother anyone else

Never use revert in a public branch!!

Reference: juejin. Cn/post / 684490…