问题
A coworker accidentally committed a large binary file which has no business being in source control thus causing the repository to be unusually large. He then pushed this commit to the common server and since then there were a bunch of other commits and pushes. I'm looking for a way to undo that commit or just remove the binary file from it on the remote so that the repository would regain its usual size.
Our common remote is at assembla.com so I don't have direct shell access to it, just git.
Assuming this is possible, what would be the consequences for other downstream nodes? Will everybody need to clone a fresh repository? (That's fine if that's the case)
回答1:
You could rebase your branch to remove the false commit. Then you have to use a forced push to push that rebased branch to the repository at Assembla. All developers then either would have to do a fresh clone or to fetch the remote branch and then do a hard reset of their local branch to the new remote branch.
Basically the commands would be (not necessarily complete):
To remove the false commit:
git rebase -i $(commit id before false commit)
git commit
git push -f origin master (assuming that the branch is master and the remote at assembla is called origin)
git rebase -i will start the interactive rebase mode where you can remove the commit.
To update a developer's clone:
git fetch
git reset --hard origin/master
Or just do a fresh
git clone $(repositoryurl)
Here comes the big fat BUT:
When you do that, you should definitely inform all developers to commit and push their work, before you do the changes. Then do a backup from the old repository, so you're able to restore it, if anything goes wrong
来源:https://stackoverflow.com/questions/26009568/git-how-to-rewrite-a-remote-history