H
H
HabrDima202020-10-16 18:10:40
git
HabrDima20, 2020-10-16 18:10:40

A large >100 mb file got into Git commit how to delete?

Git commit got a file> 100 mb how to delete?
I need to remove it from a commit, but there were more commits after that commit!
Commits must remain, but files must either be uploaded or deleted

050d105 [email protected]{10}: reset: moving to HEAD 050d105 HEAD
@{11}: Branch: renamed refs/heads/master-2 to refs/heads/master {14}: Branch: renamed refs/heads/master to refs/heads/master-2 050d105 [email protected]{16}: Branch: renamed refs/heads/master-2 to refs/heads/master 050d105 [email protected]{18}: Branch: renamed refs/heads/master to refs/heads/master-2 050d105 [email protected]{20}: Branch: renamed refs/heads/master to refs/heads/master 050d105 [email protected]{22}: reset: moving to HEAD~ 1 fcf55bd [email protected]{23}: commit: add view/options 050d105 [email protected]{24}: Branch: renamed refs/heads/master to refs/heads/master


[email protected]{23} files are needed here!!!! disappeared after git reset --hard HEAD~1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yuriev, 2020-10-16
@HabrDima20

I will answer a little more than you ask:
A specific file (www/video/route.mp4):

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch www/video/route.mp4 ' --prune-empty --tag-name-filter cat -- --all

File by mask (*.mp4):
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch "*.mp4" ' --prune-empty --tag-name-filter cat -- --all

Directory (www/video):
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch www/video -r' --prune-empty --tag-name-filter cat -- --all

This method is not optimal, but universal - it will check the entire history of commits and cut out these files / directories from the commits and rewrite everything that is next Push
force send all branches to the repository do
git push origin --force --all
not forget to tell other developers what to do somewhere and practice). I don't want to feel guilty if you drank something of historical value. git reset --hard origin/...

T
toxa82, 2020-10-16
@toxa82

Removing the passwords.txt file from all commits

git filter-branch --tree-filter 'rm -f passwords.txt' HEAD

See "Removing a file from each commit"
for details. Note that you are changing the history and you will not be allowed to git push, you will have to do git push -f. The rest of the team will have to do
git fetch && git checkout master && git reset --hard origin/master

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question