Images corrupt after git push

后端 未结 1 525
日久生厌
日久生厌 2021-01-31 03:11

I added some .png images to my git repo and then pushed them to my remote repository. I noticed that the images are in the remote repository, but they are broken.

In or

相关标签:
1条回答
  • 2021-01-31 03:53

    I had this issue too - here's a generic .gitattributes that looks generally safe for php web repos that worked for me: https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes

    running git check-attr --all -- path/to/png before and after adding the new gitattributes showed that the image file was originally treated as a text file, and now it's binary (note I had to commit/push the .gitattributes file for it to take effect on remote)

    In case the link goes dead:

    # These settings are for any web project
    
    # Handle line endings automatically for files detected as text
    # and leave all files detected as binary untouched.
    # * text=auto
    # NOTE - originally I had the above line un-commented.  it caused me a lot of grief related to line endings because I was dealing with WordPress plugins and the website changing line endings out if a user modified a plugin through the web interface.  commenting this line out seems to have alleviated the git chaos where simply switching to a branch caused it to believe 500 files were modified.
    
    #
    # The above will handle all files NOT found below
    #
    
    #
    ## These files are text and should be normalized (Convert crlf => lf)
    #
    
    # source code
    *.php text
    *.css text
    *.sass text
    *.scss text
    *.less text
    *.styl text
    *.js text
    *.coffee text
    *.json text
    *.htm text
    *.html text
    *.xml text
    *.svg text
    *.txt text
    *.ini text
    *.inc text
    *.pl text
    *.rb text
    *.py text
    *.scm text
    *.sql text
    *.sh text
    *.bat text
    
    # templates
    *.ejs text
    *.hbt text
    *.jade text
    *.haml text
    *.hbs text
    *.dot text
    *.tmpl text
    *.phtml text
    
    # server config
    .htaccess text
    
    # git config
    .gitattributes text
    .gitignore text
    .gitconfig text
    
    # code analysis config
    .jshintrc text
    .jscsrc text
    .jshintignore text
    .csslintrc text
    
    # misc config
    *.yaml text
    *.yml text
    .editorconfig text
    
    # build config
    *.npmignore text
    *.bowerrc text
    
    # Heroku
    Procfile text
    .slugignore text
    
    # Documentation
    *.md text
    LICENSE text
    AUTHORS text
    
    
    #
    ## These files are binary and should be left untouched
    #
    
    # (binary is a macro for -text -diff)
    *.png binary
    *.jpg binary
    *.jpeg binary
    *.gif binary
    *.ico binary
    *.mov binary
    *.mp4 binary
    *.mp3 binary
    *.flv binary
    *.fla binary
    *.swf binary
    *.gz binary
    *.zip binary
    *.7z binary
    *.ttf binary
    *.eot binary
    *.woff binary
    *.pyc binary
    *.pdf binary
    
    0 讨论(0)
提交回复
热议问题