A
A
ajlee42020-10-02 23:47:42
git
ajlee4, 2020-10-02 23:47:42

How to remove the last commit from the server while keeping it in the locale?

I made a commit and pushed a lot of extra code to the server. I want to delete this commit on the server, but so that everything is saved locally on my computer, how can I do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daria Motorina, 2020-10-03
@glaphire

Perhaps there is an elegant way, but the way "on the fly" is this:
backup a local branch with a new name;
in original local branch do git reset --hard HEAD^;
If anything - clean the branch according to the full state of the last commit and do git -f push origin;
Check that now everything is as it should be on the server;
Delete the original local branch;
Rename the local backup branch to the old original branch;
Set the upsteam of the new local branch to the server branch.
The penultimate step is optional, just to keep everything as much as possible as before

E
egor_nullptr, 2020-10-03
@egor_nullptr

git checkout -b backup
git checkout -
git reset --hard HEAD^1
git push --force origin HEAD

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question