Question

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

Was it helpful?

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.

OTHER TIPS

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

You can revert the unwanted commits.

git revert commit

This will create another commit that reverts the unwanted changes. After you revert the unwanted commit, you should push to origin.

You can look for --no-commit parameter for reverting also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top