본문 바로가기

version control

git attributes가 뭐야?

목차

    1. 실제 사용 예시들 

    /**Symfony Framework 프로젝트의 .gitattributes파일 **/
    
    /src/Symfony/Contracts export-ignore
    /src/Symfony/Bridge/PhpUnit export-ignore
    /src/Symfony/Component/Mailer/Bridge export-ignore
    /src/Symfony/Component/Messenger/Bridge export-ignore
    /src/Symfony/Component/Notifier/Bridge export-ignore
    /src/Symfony/Component/Runtime export-ignore
    
    /**Laravel Framework 프로젝트의 .gitattributes파일 **/
    
    * text=auto
    
    /.github export-ignore
    /bin export-ignore
    /tests export-ignore
    .editorconfig export-ignore
    .gitattributes export-ignore
    .gitignore export-ignore
    .styleci.yml export-ignore
    CHANGELOG-* export-ignore
    CODE_OF_CONDUCT.md export-ignore
    CONTRIBUTING.md export-ignore
    docker-compose.yml export-ignore
    phpunit.xml.dist export-ignore
    
    /**ElasticSearch 프로젝트의 .gitattributes파일 **/
    
    CHANGELOG.asciidoc  merge=union
    
    # These files contain expected text output, and should not be changed on
    # Windows
    build-tools-internal/src/test/resources/org/elasticsearch/gradle/internal/release/*.asciidoc text eol=lf
    
    /**Spring Framework 프로젝트의 .gitattributes파일 **/
    
    # Normalize line endings to LF.
    * text eol=lf
    
    # Ensure that line endings for multipart files in spring-web are not modified.
    *.multipart -text
    
    # Ensure that line endings for DOS batch files are not modified.
    *.bat -text
    
    # Ensure the following are treated as binary.
    *.gif   binary
    *.jar   binary
    *.jpeg  binary
    *.jpg   binary
    *.png   binary
    *.vsd   binary

    아래 참고문헌엔 더 다양한 예시들이 있다. 

    2. 속성(크게 3가지)

     

    2.1. 바이너리파일(binary)

     어떤 파일이 바이너리 파일인지 Git에게 알려줄 수 있다. 

    모든 pbxproj 파일을 바이너리로 파일로 취급하는 설정은 아래와 같다. .gitattributes 파일에 넣으면 된다.

    *.pbxproj binary

    이제 pbxproj 파일은 CRLF 변환이 적용되지 않는다. git show  git diff 같은 명령을 실행할 때도 통계를 계산하거나 diff를 출력하지 않는다.

    이로 인해서 바이너리 파일도 diff해질 수 있어진다.

    2.2.  저장소 익스포트하기(export-ignore)

    2.3.  Merge전략 (merge=*)

    ex) merge=ours

     

    참고문헌 

    https://git-scm.com/book/ko/v2/Git%EB%A7%9E%EC%B6%A4-Git-Attributes

    https://github.com/alexkaratarakis/gitattributes