Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git remove commit on the server

Tags:

git

git-reset

i've made some mistakes about my project managed in git:

reading some guides and some posts here I made this command:

git reset --hard a77ec5f

where the commint a77ec5f is the last 'good' commit

after this, the files are right in my local copy, but if I do a git status:

$ git status
# On branch dev
# Your branch is behind 'origin/dev' by 4 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)

and now, how can I tell the server that the 4 commits that I'm behind are to remove? thanks

like image 662
ghiboz Avatar asked May 20 '26 04:05

ghiboz


2 Answers

If your repository is synced by others, then you should not push any history changes unless you are certain nobody has pulled the bad changes yet.

To rewrite history (dangerous), do an empty commit locally (git commit --allow-empty) to diverge your HEAD from the remote HEAD, then push --force to rewrite the server's history.

like image 196
nneonneo Avatar answered May 22 '26 17:05

nneonneo


you should not remove the commits on your server, but revert them

like image 43
Marian Theisen Avatar answered May 22 '26 19:05

Marian Theisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!