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)
You can modify the most recent commit in the same branch by running git commit –amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit –amend to modify the most recent commit.
If you want to restore the project's history as it was at that moment in time use git reset --hard <SHA> If you want to recreate one or more files in your working directory as they were at that moment in time, without altering history use git checkout <SHA> -- <filename>
The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history. This is a rather dangerous process, because it's very easy to overwrite (and thereby lose) commits from your colleagues.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With