问题
Alright - so I had a guy (in a school project - don't panic) commit a full eclipse workspace complete with .class files and .settings/ directories. What I did was to clone the repo and make a .gitignore file and issue :
$ git reset --soft HEAD^
$ ... unstaged all files and added .gitignore and all files that it filtered in ...
Then I tried :
$ git commit -c d1cf2d8173234b444c601d5e294a5cf6d790fa2c
Where the SHA is the SHA of the online commit. It won't let me push :
Pushing to https://USERNAME@git.assembla.com/PROJECT.git To https://USERNAME@git.assembla.com/PROJECT.git ! [rejected]
master -> master (non-fast-forward) error: failed to push some refs to 'https://USERNAME@git.assembla.com/PROJECT.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
My question is what should I have done instead ?
So how exactly should I go about deleting a commit in this scenario. Do not warn me that it shouldn't be done - in this case it is very well acceptable, recommended and necessary to edit the history (I want to reclaim the space in the online repo). Also - I am not really worried how to force the push - I want the easier/cleaner way of replacing the remote HEAD commit with another.
It all starts with a clone...
回答1:
Aside from having to get the remote repo admins to allow you to rewind the "master" branch, see http://help.github.com/remove-sensitive-data/ and in particular, the "cleanup and reclaiming space" section.
It's often simplest to start over with a new remote and have the remote-admins delete the old one entirely, in cases like yours. :-)
回答2:
You could use the --force flag in your push statement, but it is risky if others are using the same repo. Otherwise, you may want to update back to the remote head and use a Git revert.
来源:https://stackoverflow.com/questions/10372179/git-head-commit-in-remote-repository-is-crap-how-exactly-should-i-go-about-r