2. 파일 변화를 시간에 따라 기록했다가 나중에 특정 버전을 다시 불러올 수 있는 시스템
버전 관리 시스템
3. 버전 관리 시스템
Version Control System
Version Database
File
checkout
Version 1
Version 2
Version 3
Local Computer
로컬 VCS
4. 중앙집중식 버전 관리 시스템
Central Version Control System
Version 1
Version 2
Version 3
File
Local Computer
File
Local Computer
Version Database
중앙 VCS 서버 File
Local Computer
File
Local Computer
Version 1
Version 2
Version 3
5. 분산 버전 관리 시스템
Distributed Version Control System
Version 1
Version 2
Version 3
Version Database
Server Computer
Version 1
Version 2
Version 3
File
Local Computer
Version Database
Version 1
Version 2
Version 3
File
Local Computer
Version Database
Version 1
Version 2
Version 3
File
Local Computer
Version Database
Version 1
Version 2
Version 3
File
Local Computer
Version Database
Version 1
Version 2
Version 3
7. Online Source Control
Longer time to store because all of the data is
stored in a centralized repository.
Offline Source Control
Extremely fast because complete copy of the
data is stored locally in the client’s system.
CVCS DVCS
8. SVN data flow Git data flow
Working
Directory
Remote
Repository
Merge
Rsync
(Remote Sync)
Remote Repository
Local Repository
Index
push
commit
add
fetch
checkout
HEAD
Working Directory
pull
CVCS DVCS
9. The way SVN thinks about its data The way Git thinks about its data
CVCS DVCS
각 파일에 대한 변화를 저장 시간 순으로 프로젝트의 스냅샷을 저장
Version1 Version2 Version3 Version4 Version5
코끼리
호랑이
곰
오렌지
코끼리
→ 물개
오렌지
→ 사과
물개 →
코끼리
곰
→ 사람
사과
→ 나무
Version1 Version2 Version3 Version4 Version5
코끼리
호랑이
곰
오렌지
물개
Version 1
의 호랑이
Version
1의 곰
사과
코끼리
호랑이
사람
Version 2
의 사과
Version4
의 코끼리
Version4
의 호랑이
Version
4의 사람
나무
호랑이
→ 지렁이
Version
2의 물개
지렁이
Version
1의 곰
Version 2
의 사과
지렁이
→ 호랑이
11. Working directory
워킹 디렉터리
현재 작업 공간
프로젝트의 특정 버전에 체크아웃
Add 하기 전
Staging Area (=Index)
스테이징 영역
Commit 하려고 준비하는 공간
스냅샷을 만든다.
Add 직 후 Commit 직 전
.git directory
Local repository
스냅샷을 저장한다.
git init or git clone으로 생성됨
Commit 이후
Modified
Staged
Committed
Remote Repository
.git directory
공유되는 저장 공간
Hosting service 존재
ex. VSTS, Github, Bitbucket
Push 이후
로컬 환경
네트워크 환경
Untracked Tracked
1
2
3
13. Working directory
워킹 디렉터리
Staging Area (=Index)
스테이징 영역
.git directory
Local repository
Remote Repository
.git directory
로컬 환경
네트워크 환경
stash
stash
branch / checkout / cherry-pick
reset
revert
rebase
merge
log
diff
show
3 단계 모두에서 사용 가능
15. 변경 되돌리기
git reset (HEAD) <file>
*git reset (HEAD) .
Modified
Working directory
워킹 디렉터리
Staged
Staging Area
스테이징 영역
add
Git add 했던 파일(들) 워킹 디렉터리로 되돌리기
16. 변경 되돌리기
git checkout -- <file>
*git checkout -- .
Modified
Working directory
워킹 디렉터리
Modified 파일 Unmodified 상태로 되돌리기
Unmodified
Working directory
워킹 디렉터리
Modify
17. 변경 되돌리기
git stash
git stash pop
변경 사항 잠시 보류하기
Stash stack
0
1
**Modified이면서 Tracked 상태인 파일과 Staging area에 있는 파일만 push 한다.
Modified
Working directory
워킹 디렉터리
add
Staged
Staging Area
스테이징 영역
20. Commit --amend
Working directory
워킹 디렉터리
Staging Area
스테이징 영역
.git directory
Repository
Modified
Staged
Committed
commit --amend1
3 commit
2 수정 작업
8c58793
9f5a468
4 새로운 커밋 생성
21. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
중간 커밋 수정하기
git rebase –i master
-i 플래그가 없으면 이 영역의 커밋을 모두 한번에 Rebase
-i 플래그가 있으면 커밋을 특정하여 잠시 멈추게 할 수 있다
23. git rebase –i master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
각 스텝에서 뭔가 처리를 마치고 다음 커밋으로 스텝을 넘어가고 싶을 때
git rebase --continue
git rebase --skip
git rebase --abort
변경 처리를 마침
변경 하지 않고 그냥 넘어감
리베이스를 취소함 (모든 스텝을 취소함)
11’
git add . & git rebase --continue
git rebase --skip
git rebase --abort
24. 중간 커밋 수정하기
git rebase –i master
Interactive rebase (대화형 리베이스)의
사용 법은 여기 다 있음
Pick = 수정 안 함.
Reword = 메시지만 바꿀 거임!
Edit = 코드나 파일 수정 좀 함!
Squash = 앞 커밋이랑 하나로 합칠 거.
메시지는 내가 고를 거임.
Fixup = squash랑 똑같은데, 앞 커밋의 커밋 메시지 쓸 거임.
지금 꺼 메시지는 버릴 거임.
Exec = 잠깐 shell 명령 실행할 거임.
(ex. 이전 커밋에서 테스트 돌려보고 싶을 때)
Drop = 버림.
----------------------------------------------------------------------------------
Rebase 실행 순서는 위 -> 아래임. 커밋 순서 재정렬 할 수 있음!
여기 있는 커밋 줄 지우면 그 커밋은 영영 바이바이임.
근데 다 지우면 이 리베이스는 걍 없던 일로 함.
빈 커밋(변경 사항 없는 커밋)은 주석 처리함.
31. 중간 커밋 수정하기
(응용) Edit이 무서울 때,
커밋을 본격 수정하기 전에 일단 한번 코드만 적용해보고 싶을 때
1. branch를 새로 판다 (git checkout -b rebase-practice)
2. 맘껏 edit 해 본다.
3. 맘에 들면 원래 브랜치 이름으로 바꾼다 (git branch –m hs/104-work-branch)
3’. 맘에 들지 않으면 연습 브랜치를 그냥 버린다.
1. 일단 코드를 수정하고, commit 한다.
2. git rebase –i maser
3. 맨 마지막에 추가한 커밋에 fixup 혹은 sqush 플래그를 설정한다.
4. 수정하고 싶었던 커밋의 바로 뒤로 순서를 조정한다.
5. 수정하고 싶었던 커밋과 합쳐지며 edit한 것과 같은 효과를 볼 수 있다.