background

Scenario 1: Multiple incorrect commits were committed and you want to roll back to a previous commit.

Case 2: Merge the wrong branch and want to roll back to before merge.

The solution

Git reset current branch to here

You can directly operate on IDEA.

Git reset current branch to here

Now to simulate, say you committed four times, and now you want to roll back to the first commit and get rid of the next three commits,

Select a commit and right-click

Select Hard to roll back to a commit.

Now the local has been completed, the next three commit records have been deleted, can not be seen.

Push to enforce (force push)

Found that force push is gray, force push cannot be.

Because it’s protected, take it away, and you’re done.

After another push, the next three commits of the remote repository are deleted.


The way gitlab removes the protection is

reference

zhuanlan.zhihu.com/p/358145704


www.jetbrains.com/help/idea/u…

Solutions to various situations of rollback, based on IDEA.