Git error, need to remove large file

前端 未结 8 614
北恋
北恋 2021-02-01 05:37

I am getting this error when I try to push to git and I have no idea how to fix it.

Counting objects: 1239, done.
Delta compression using up to 4 threads.
Compre         


        
相关标签:
8条回答
  • 2021-02-01 05:53

    I faced the same issue recently, you can actually just filter the branch for specific file and remove it -

    git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
    
    0 讨论(0)
  • 2021-02-01 05:54

    git reset --soft HEAD~1

    then exclude the file from the commit.

    Note: Use HEAD~N to go back to N number of previous commits.

    use this , go back a commit ,remove the large file from the commit if you can see it , then re commit and push.

    this should solve the problem

    0 讨论(0)
  • 2021-02-01 05:54

    Adding to the previous answers:

    git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_to_the_file/your_big_file'
    

    Additionally, when I tried to pull I got "Refusing to merge unrelated histories".

    Solution was to use:

    git pull origin branch_name --allow-unrelated-histories
    

    Then solve your possible conflicts, and push this time without the big_file.

    0 讨论(0)
  • 2021-02-01 05:55

    You can revert git add before commit.

    Check this question: How to undo 'git add' before commit? It should work. And don't send big files to git, it's not worthy ;)

    Also, exclude your logs, by adding git ignore on your logs path.

    0 讨论(0)
  • 2021-02-01 05:55

    @Daniel

    You can ignore that log(s) file from git repo using .gitignore file. for that you have to add below line to your .gitignore file

    /log
    

    and try to commit again.
    Hope this details help you to fix your issue.

    0 讨论(0)
  • 2021-02-01 05:58

    Adding to the previous answers:

    We are going to remove the large file from the commit as you said

    1. Do the push from the terminal just to get the large file path git push --set-upstream origin Remote_branch_name, locate the large file path in the errors, something like RepositoryName/folders.../bigFileName.

    2. Remove the file from all the branches, git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_and_big_file' past the path that we found in section one instead of path_and_big_file.

    3. Execute git pull origin branch_name --allow-unrelated-histories to not get unrelated histories error

    4. Now try to push to git, it should work

    0 讨论(0)
提交回复
热议问题