I made a mistake .... and I don't know how to fix it.
I explain the issue.
I was working on my project, and I did a first commit. In this commit 2 big useless files had been added... I didn't wanted these files so I did a
git rm file
Then commited again. And I'm stupid, because I pushed to github hehehe :).
I think you've found out the problem...
How can I remove definitively these files from my local and github repositories (especially github...)
I found some help on the internet, but I don't want to break all my repository.
Thanks
To undo multiple commits that are in a remote repository, you can use a cool command called rebase, which allows you to interactively pick what commits you want to keep or discard. You just have to give rebase a starting point. Use the git log –oneline command to check for the hash you want to use as a starting point.
When you want to completely remove the last commit, you need to mention the commit id of the one before last. Then push your new branch up to the remote repo if you have a remote. If you just want to remove the commit but keep the changes of that commit, then git reset <COMMIT_ID> will work.
If no one else has pulled, you should just get your local branch back to how you want it (probably by either resetting to a previous position, or by doing an interactive rebase to remove the unwanted commit), then push again to github with the -f
(force) option:
git push -f <remote-name> <branch-name>
If other people have pulled, the usual advice applies: read the recovering from upstream rebase section of the git-rebase man page to see what you're doing to the others before you do your forced update.
If you wanted remove (not revert, remove) last commit with new files, I think you should do:
git reset --soft "HEAD^"
Anyway since you already pushed it to github, you can't remove it without re-creating git repo. This is how it work, you can revert each commit, for example commit where you deleted those 2 big files. Since it's new repo and you are talking about initial commit, re-creating repo looks for me as best idea.
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