티스토리 뷰
1. Git Tagging
- tag : static pointer
- 레퍼지토리의 중요한 포인트에 tagging을 달 수 있음
✅ Creating tags
Lightweight
- git tag [tag_name]
Annotated
- git tag -a[tag_name] -m ‘tag_massage’
- 이름과 부가 정보 추가
✅ 명령어
git tag -a[tag_name][commit checksum] -m ‘tag message’
- 이전 커밋에 태그 붙이기
git tag -d[tag_name]
- 레퍼지토리에서 태그 삭제하기
git tag -l(소문자 L)
- 레퍼지토리의 모든 태그 출력
git checkout [tag_name]
- HEAD를 해당 태그가 가리키고 있는 파일의 버전으로 이동
- “detached HEAD” dangling pointer 문제 발생 가능
2. Git Branching
- Branch : 최신 commit object를 가리키는 가벼운 포인터
- Branching : 메인 라인으로부터 diverging한 후 main line에는 영향을 주지 않으면서 작업을 이어나가는 것
- 주로 hotfix를 위해 사용
- hotfix가 끝나면 생성된 branch는 main line으로 merged
- git init시 branch는 항상 default로 1개 생성(== main(master))
- Head : 작업중인 work branch를 가리키는 포인터
- tag와의 차이점
- static인 tag에 비해 branch는 movable 포인터
- 커밋할 때마다 bracnh가 이동
- 주의점
- master branch에서는 작업을 수행하지 않음(master는 항상 stable version)
✅ 명령어
git branch -v
- 존재하는 브랜치 리스트 업
git branch new_brance_name
- 주어진 이름의 새로운 branch 생성
- 생성된 브랜치는 현재 작업하고 있는(head가 가리키는 branch가 가리키는 commit branch) 커밋을 가리키게 됨
- head는 여전히 master를 가리킴 → 생성한다고 바로 switch되지 않음
git checkout branch_name
- 주어진 이름의 branch로 head 이동(switch)
git branch -d branch_name
- 주어진 이름의 branch 삭제
git branch --move ‘old’ ‘new’
- 브랜치 이름을 old에서 new로 변경
✅ Git Merge
git merge branch_name
- 현재 작업 중인 branch와 branch_name을 merge
git reset --hard <commit checksum>
- <commit checksum> 상태로 되돌아가기
merge 유형
- Fast-forward merging
- 현재 branch(master)가 합치려는 branch의 직접적인 ancestor인 경우
- sequential workflow의 경우 적용
- 합치려는 branch가 가리키는 commit으로 현재 작업중(master)인 branch 이동
- 현재 branch(master)로 merged 된 branch는 삭제할 수 있음
- Three-way merging
- 분기점이 생성된 경우
- merge 시 새로운 commit(스냅샷)을 생성한 후 현재 branch(master) 이동
- 현재 branch(master)는 새로운 commit을 가리키게 됨
3. Handle Conflict
- simple solution
1) 충돌이 일어난 두 브랜치 중 한 브랜치를 선택하여 나머지 브랜치의 변화값은 삭제(선택된 브랜치의 변화값만 적용)
→ 충돌은 해결했으나 아직 commit object(ex. Commit 5)는 생성되지 않았음
2) commit the changes
'Git' 카테고리의 다른 글
Git Basics (1) | 2023.11.02 |
---|---|
CMD | 깃&깃허브 사용법 (0) | 2021.08.21 |