Git

[Git Project Reading Skill] 오픈소스 읽어들이기 : 명령어 위주

Blue___ 2021. 8. 1. 00:31

 

 

 

개발자가 오픈소스를 읽는 방법

 

 

프로젝트 소스코드 clone(다운로드) 및 확인
$git clone [git url]
cd [git clone folder 위치] # dir 이동

 

 

git Reading Log #1
#해당 오픈소스에서 누가 개발을 많이하는지 검색
# nl : line number 명시
$git shortlog -sn | nl

# git shortlog -s 옵션 : 개발자별 commit 개수 요약
$git shortlog -h | grep summary
$git shortlog -s

# git shortlog -n 옵션 : 개발자별 commit 개수 순위 정리
$git shortlog -h | grep number
$git shortlog -n

 

git Reading Log #2

- 전체 소스파일 수정 내역(Commit) 개수 세기

- Merge Commit은 수정내역이 없다 => 병합커밋

 

# 전체 소스파일 수정내역(commit) 개수 세기
# wc -l 명령 :  라인 수 개수 측정
# wc -l 없을경우 그냥 커밋 리스트
$git log --oneline | wc -l

# 특정 폴더를 기준으로 commit list 확인
$git log --oneline -- [특정폴더]

# 특정 날짜를 기준으로 commit list 확인(inclusive:이상이하)
$git log --oneline --after=2020-01-01 --before=2020-06-30

#전체 소스파일 commit 자세히 보기
$git log -p

#소스파일 commit 처음부분부터 확인
$git log --reverse

# 커밋 내역 하나 확인
# SHA1 커밋 암호화 값가져와서 show
$git show 6c8e2ba

# 6c8e2ba 커밋의 수정 사항사항 확인
$git show 6c8e2ba | grep "diff --git"

# 6c8e2ba 커밋의 수정 파일 개수
$git show 6c8e2ba | grep "diff --git" | wc -l

 

 

git Writing #1
# 방금 commit 수정한 부분
$git diff

# 내가 작성한 commit 확인
$git show

 

오픈소스 프로젝트에 commit 작업 PR(PullRequest) 하기
# 브랜치 따기
# 브랜치명은 작업을 대표하는 내용이면 좋다
$git checkout -b [브랜치명]

# 브랜치확인
$git branch

# pull request 준비 
# commit push
$git push origin [브랜치명]

# 이후 GUI로 PR진행

 

commit 명령어
# commit 정보 삭제
#  HEAD~1은 가장 위에서 첫번째 내용을 삭제
$git reset --hard HEAD~1

# commit에서 라이센스 포함 commit
# -s 옵션 포함시 라이센스 서명을 의미하는 Signed-off-by내용 기입
$git commit -sm "[commit message]"

# commit 수정하기
$git commit --amend

 

오픈소스 Github 최신 commit으로 Base 업데이트 하기
# 오픈소스 공식 Github 프로젝트 URL을 upstream으로 등록한다
$git remote add upstream [git url]

# origin : 나의 Fork저장소 github URL
# upstream : 오픈소스 공식 github URL
$git remote -v


## rebase 하기
# 1. 공식 upstream 저장소에서 최신 commit history 가져온다
$git fetch upstream master

# 2. 최신 commit history를 기준으로 베이스 갱신 => rebase
$git rebase upstream/master

# 3. Fork한 저장소(Github)수정 => PR 자동 갱신
$git push --force origin [브랜치명]

 

submodule 설정
//서브모듈 생성
git submodule add https://github.com/{사용자명}/{저장소명}.git {폴더명}

//서브 모듈 연동
git submodule update --init --recursive

//서브 모델 업데이트
git submodule update

 

 

 

 

 

 

 

 

 

 

 

반응형