How does git delete the last bad commit of a remote repository?

Suppose you have 3 commits as follows:

commit 3
commit 2
commit 1

where the last commit commit 3was wrong, then you can execute:

git reset --hard HEAD~1

You will find, HEAD is now at commit 2.

Then use git push --forceto force this change to the server. This way the last bad commit on the server is completely gone.

It is worth noting that this type of operation is more dangerous. For example, after your commit 3, someone else submits a new one commit 4. After you force the push, the friend's one commit 4also disappears.

 

Quoted from https://segmentfault.com/q/1010000002898735

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325105672&siteId=291194637
Recommended