Home > OS >  Git Remove Added Commits with Large Files
Git Remove Added Commits with Large Files

Time:11-10

I accidentally added some large files into my git commit. After this I have deleted the large files and now I want to commit the remaining changes (excluding the large files) but somehow the deletion of the large files are still in my git history and therefore I cannot make any further commits. I do not want to git reset HARD or something and lose a lot of my local changes. How do I resolve this?

My steps:

git add -A
git commit -m "Commiting with Large Files"
git push origin main
-- Failed to push due to Large files

Now I delete these large files from my local machine and try to push again

git add -A
git commit -m "Commiting with deleted large files"
git push origin main
-- Failed to push 

I tried

git reset --soft HEAD~1
git reset

but I still have the deleted files as unstaged changes which is preventing from a new git add -A and push.

Unstaged changes after reset:
D   largefile/b_qty.tar.gz
D   largefile/b_qty.txt
D   largefile/s_qty.tar.gz
D   largefile/s_qty.txt 

Any suggestions on how to fix this? I really cannot lose any of my local changes.

CodePudding user response:

Try to use git restore --staged .

To unstage files or to unstage a specific file use

git restore --staged <individual_file>

CodePudding user response:

If I understand well, you have the following commits:

def - Commiting with deleted large files
abc - Commiting with Large Files

so when you undo the commit def, it is normal that git still sees these files as deleted: you still have commit abc where you added those files.

If you want to get a nice view of your commit graph, try:

git log --all --graph --oneline --decorate

This will help you diagnose. Probably you should rewrite both of your commits, so

git reset HEAD~2

might do the trick, but again: analyze your git graph to see what you need to do, which commits to reset,...

  • Related