I committed a very large file together with my regular files. I want to make the remote forget the commit I just did but all the tutorials I find talk about reverting to a previous commit, which will make me loss all my changes. I just want to delete the commit but keep the changes, then I can add the large file to gitignore and push the changes
-
11) Make a backup of your repository, then try 2) `git reset --soft HEAD~1` – Lasse V. Karlsen Oct 13 '19 at 18:53
-
2Possible duplicate of [How do I revert a Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit) – u_mulder Oct 13 '19 at 19:06
-
The commit contains the changes, so there's no way around deleting them. – wjandrea Oct 13 '19 at 19:16
1 Answers
As I understand your want to delete your last commit which contains your new large file (I assume you have only this file in your commit), so:
A- if you can force commit on remote repository (and if you won't make a mess to your colleagues in a case they have already pulled your commit):
1- Delete the last commit without losing changes: git reset HEAD~1
2- Add your large file to .gitignore
, your can add it in
.git/info/exclude
instead, to ignore the file locally in your
working copy.
3- Commit .gitignore
if your have changed it.
4- git push --force origin <your_branch>
B- if you can't/won't use git push --force
:
1- Make Copy of your file somewhere outside of your local repository.
2- Revert the last commit:
git revert HEAD
3- Bring your file back to your local repository.
4- Add it to your .gitignore
or .git/info/exclude
(as you like!).
5- git push origin <your_branch>

- 2,853
- 2
- 27
- 36
-
Agree about your approach here, but keep in mind with B the large file will still be cloned whenever the repository is cloned in the future, as it exists in the revision history now. – robsiemb Oct 13 '19 at 20:50