1

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

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150

1 Answers1

1

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>

O.Badr
  • 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