gitgit-reset

git remove commit on the server


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


Solution

  • 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.