2012년 4월 14일 토요일

Git(Version control system)

1. Git

        Git is distributed version control system focused on speed, effectivity and real-world usability on large projects

2. 서버 설치

    2.1. 리눅스 계열(우분투)

        2.1.1. 설치 (root)

            ] # apt-get update
            ] # apt-get install git gitosis

        2.1.2. 사용자 추가 및 저장소 생성 (root)

            ] # adduser --system --shell /bin/bash --gecos 'git SCM user' --group --disabled-password --home /home/git git
            ] # su git
            ] $ mkdir /home/git/repositories

        2.1.3. 인증키 생성 (user)

            ] $ su ${UserID}
            ] $ ssh-keygen -t rsa -C "${UserID}"
            ] $ scp /home/${UserID}/.ssh/id_rsa.pub ${AdminID}@${AdminHost}:${UserID}.pub

        2.1.4. gitosis-init 실행 (user)

            ] $ sudo -H -u git gitosis-init < userid.pub
            ] $ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

        2.1.5. 저장소 다운로드 (user)

            ] $ git clone git@${GitServerAddr}:gitosis-admin.git
            ] $ cd gitosis-admin

    2.2. Windows 계열

    2.3. 서버 사용

        2.3.1. 프로젝트 관리

            ] $ cd gitosis-admin
            // 환경 설정 파일 수정(프로젝트 추가/수정/삭제 등.)            ] $ vi gitosis.conf

{
            [gitosis]

            [group gitosis-admin]
            writable = gitosis-admin
            members = ${AdminID}

            [group ${ProjectName}]
            writable = ${ProjectName}
            members = ${UserID}         
}
            // 수정된 내역을 서버에 적용
            ] $ git commit -a -m "Added a new Project(${ProjectName})"
            ] $ git push

            // 프로젝트 디렉토리 생성 및 git 초기화
            ] $ mkdir ${ProjectName}
            ] $ cd ${ProjectName}
            ] $ git init

            // 프로젝트 디렉토리에 소스 추가
            // 만약 초기에 소스가 없으면 빈파일이라도 생성해야 함. (touch README)
            // 파일이 하나도 없으면 push 단계에서 master가 없다는 에러가 발생함.
            ] $ cp ${ProjectSource} ./

            // 소스 업로드
            ] $ git add .            // 현재 디렉토리를 포함한 모든 서브 디렉토리의 내용을 추가
            ] $ git commit -a -m "Initial import"   // Git 서버에 적용
            ] $ git remote add  origin git@${GitServerAddr}:${ProjectName}.git
            ] $ git push [origin master]             // 원격지 Git 서버에 push

3. 사용

    3.1. 소스 다운로드

         3.1.1. git 명령을 이용

                ]$ git clone git@ipaddr:Storage.git storage


    3.2. branch 사용

                 ]$


    3.3. tag 사용

        3.3.1. tag 생성

                 ]$ git tag -a ${TagName} -m "Comment"  # 태그 달기
                 ]$ git push --tags                                    # 태그 정도 업데이트(to Server)

        3.3.2. tag 제거

                 ]$ git tag -d ${TagName}      # 태그 제거
                 ]$ git push --tags                 # 태그 정도 업데이트(to Server)

    3.4. patch 사용

        3.4.1. --no-prefix 옵션

                ]$ git diff --no-prefix > ${patchfile}   # 패치 파일의 생성
                ]$ cd path/to/top                             # 패치할 소스의 최상위 디렉토리로 이동
                ]$ patch -p0 < ${patchfile}               # 패치 적용

        3.4.2. --no-prefix 옵션을 사용안함

                ]$ git diff > patchfile          # 패치 파일의 생성
                ]$ cd path/to/top              # 패치할 소스의 최상위 디렉토리로 이동
                ]$ patch -p1 < patchfile     # 패치 적용

        3.4.3. 패치 범위를 지정해서 파일 생성

                ]$ git diff ${start}..${end} > ${patchfile}          # 패치 파일의 생성

    3.5. repo 사용

        3.5.1. 소스 다운로드

                ]$ repo init -u git@${serveraddr}:${projectname}/manifest.git -b ${branchname}
                ]$ repo sync
                ]$ repo start ${branchname} --all

4. ASB