git 더하기 github(구름ide 환경)
TRANSCRIPT
GIT과�GITHUB�
Original�Octocat�-�https://octodex.github.com/original�
01�소스�코드를�어떻게�관리하고�계신가요?�
프로젝트_최종.zip�
ZIP�
프로젝트_최종_최종2.zip�
ZIP�
프로젝트_최종_최종2_마지막.zip�
ZIP�
프로젝트_최종_최종2_마지막_진짜제출용.zip�
ZIP�
02�조금�더�나은�버전?�
프로젝트_20160401.zip�
ZIP�
프로젝트_20160405.zip�
ZIP�
프로젝트_20160510.zip�
ZIP�
프로젝트_20160514.zip�
ZIP�
프로젝트_20160401_이준영.zip�
ZIP�
하지만�혼자가�아니라면�어떻게�될까?�
프로젝트_20160401_송태웅.zip�
ZIP�
프로젝트_20160401_이준영+송태웅_통합.zip�
ZIP�
03�버전�관리(Version�Control)�
소스코드에서�무엇이�변경되었는지?��
누가�소스코드를�변경했는지?��
언제�소스코드가�변경되었는지?��
왜�그렇게�바뀐건지?��
이전�버전으로의�복구는�어떻게?��…�
그래서�씁니다.�버전�관리�시스템�
04�Git?�
분산�버전�관리�시스템�
리누스�토발즈가�개발�
빠름!�
완전한�분산�환경�지원�
대규모�프로젝트에도�사용�가능�
05�GitHub?�
GitHub�:���Git�저장소�호스팅�서비스�
- 공개�저장소는�무료�
- 강력한�협업�기능�제공�
- 오픈�소스�소프트웨어의�허브�
- 확장이�용이�
- 다양한�서비스와의�연동�
- 기업을�위한�엔터프라이즈�버전�제공�
06�Octocat��https://octodex.github.com�
07�GitHub�외에도…�
Git�시작하기�
Octobiwan�-�https://octodex.github.com/octobiwan�
전에…�
01�시작하기�전에��GitHub,�구름�IDE�회원�가입과�세팅�
http://www.slideshare.net/ssusercef361/git-github-61998192�
위의�URL에서�참고해�주세요.�
02�환경�설정��[파일]�>�[새�프로젝트]�
03�환경�설정��새�프로젝트�>�Java�콘솔�프로젝트�
05�환경�설정��새�프로젝트�>�프로젝트�정보�입력�
06�환경�설정��Main�클래스�정보�수정�
07�환경�설정��[프로젝트]�>�[빌드/실행�설정]�
08�환경�설정��프로젝트�속성�>�메인�클래스�이름�변경�
09�CLI와�친해지기��터미널,�쉘
텍스트�입력�및�표시를�위한�인터페이스(텍스트�터미널)�
입력된�명령을�해석하여�운영체제로�전달�
사용자가�로그인�시�자동으로�쉘이�실행�
터미널(Terminal)�
쉘(Shell)�
현재�경로�
사용자@호스트�
터미널과�쉘의�모습�
10�CLI와�친해지기��pwd, ls, mkdir
pwd��현재�경로�확인�
ls��현재�경로의�파일�목록�보기�
mkdir �디렉토리(폴더)�만들기�$ mkdir my-folder
11�CLI와�친해지기��절대�경로,�상대�경로
최상위�디렉토리(루트,�/)를�기준으로�한�경로�
현재�위치를�기준으로�한�경로�
절대�경로�
상대�경로�
마침표�하나�(.)�
마침표�둘�(..)�
../..�
../../..�
현재�디렉토리�
상위�디렉토리�
상위의�상위?�
위의�위의�위?��
workspace
/
lotto-gen
bin
src
project
LottoGenerator.java
현재�위치�
절대�경로�/workspace/lotto-gen/src/project/LottoGenerator.java
상대�경로�src/project/LottoGenerator.java
12�CLI와�친해지기��cd�
cd��디렉토리�이동�$ cd my-folder
상위�디렉토리로�이동�$ cd ..
상대�경로로�이동�$ cd src/project
절대�경로로�이동�$ cd /workspace/lotto-gen
13�CLI와�친해지기��cat, cp
cat��파일�내용�보기�$ cat src/project/LottoGenerator.java
cp��파일�복사(mv는�이동)�$ cp src/project/LottoGenerator.java ./
14�CLI와�친해지기��rm
rm��파일�삭제�$ rm src/project/LottoGenerator.java
비어있는�디렉토리�삭제�$ rm –r my-folder
파일이�있는�디렉토리�삭제�(절대�주의!!!)�$ rm –rf <삭제할�디렉토리>
15�CLI와�친해지기��vim�에디터�
vi��vim�에디터�실행�$ vim README.md
ESC� �명령�모드로�전환�i� � �편집(삽입)�모드로�전환�dd � �줄�삭제�:wq� �저장�후�종료�:q!� � �저장하지�않고�종료�
16�쉬어가는�코너(제가)�
<복습하고�넘어가기>�
1. /workspace�디렉토리�아래에�자기�아이디로�디렉토리�생성하고�
2. 해당�디렉토리로�들어가기�
3. 디렉토리�안에�vim�에디터로�hello.txt�파일�만들고,�
4. 간단한�인사말을�쓴�후�저장하고�종료�
5. 파일�내용�출력�명령어로�출력하기�
6. 다시�/workspace/lotto-gen�디렉토리로�돌아와서�현재�위치�출력�
Git�시작하기�
Labtocat�-�https://octodex.github.com/labtocat�
01�Git�필수�개념�집어보기��Git의�세�가지�상태�
Working�Directory�현재�작업�디렉토리,�프로젝트의�특정�버전을�체크아웃한�것�
��
Staging�Area�커밋�시�반영되는�파일이�보관되어�있는�곳�인덱스�영역이라고도�하며,�커밋하면�Git�Directory(로컬�저장소)로�이동된다.���
Git�Directory�Git으로�관리되는�프로젝트의�정보와�객체�데이터베이스가�저장되는�곳�Git�명령어를�통해�최초에�초기화�하거나�다른�저장소를�Clone하면�생성된다.�
Git을�통한�작업�순서�- 워킹�디렉토리에서�파일을�수정�
- 워킹�디렉토리에서�변경된�파일을�스테이징�영역에�추가(커밋할�스냅샷�생성)�
- 스테이징�영역의�파일을�커밋하여�Git�디렉토리에�영구적으로�저장�
h"ps://git-scm.com/book/ko/v2/시작하기-Git-기초
02�Git�필수�개념�집어보기��파일의�라이프�사이클�
• Untracked�:�Git이�파일의�변경을�추적하지�않는�상태�
• Tracked�:�Git이�파일의�변경을�추적하고�있는�상태�
• Unmodified�:�수정되지�않은�상태�
• Modified�:�추적�중인�파일이�수정된�상태�
• Staged�:�스테이징�영역에�추가된�상태�
h"ps://git-scm.com/book/ko/v2/Git의-기초-수정하고-저장소에-저장하기
03�이렇게�실습해볼�예정입니다�
간단한�로또�번호�생성�프로그램을�만들어�보면서�Git�실습��
1. 로또�번호�생성�프로젝트�생성�
2. 45개(0~44)의�번호�랜덤�생성�메서드�작성�
3. 버그�발견!��생성되는�숫자�범위�조정(1~45)�
4. 버그�발견!��중복�생성된�번호�확인�로직�추가�
5. 주석�추가�
04�사용자�정보�설정��git�config�
Local Git Repository Branch Commit Logs
$ git config --global user.name “Junyoung Lee”
$ git config --global user.email “[email protected]”
git config�명령으로�사용자�이름과�이메일�설정�
Git이�커밋할�때마다�설정된�사용자�이름과�이메일�정보를�사용�
--global�옵션은�해당�시스템�전체�설정으로�적용됨�
--global�옵션을�빼면�해당�프로젝트에만�설정�
Working Directory
Staging Area
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
05�Git�저장소�만들기(초기화)��git�init�
Working Directory
Staging Area
Local Git Repository Branch Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
$ git initInitialized empty git repository in /workspace/lotto-gen/.git
git init 명령으로�저장소�생성�
git init�명령을�실행하면�.git�디렉토리가�생성됨�
$ ls –latotal 8 drwxr-xr-x 6 root root 9 5월 13 21:16 . drwxr-xr-x 3 root root 3 5월 13 16:52 .. drwxr-xr-x 7 root root 10 5월 13 21:18 .git -rw-r--r-- 1 root root 56 5월 13 21:08 README.md drwxr-xr-x 3 root root 3 5월 13 17:02 bin ...
06�추적하지�않을�파일�설정�-�.gitignore�파일�
Working Directory
Staging Area
Local Git Repository Branch Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
# Git ignorebin/ # binary filesgoorm.manifest # Goorm IDE manifest file
.gitignore 파일�추가�
lo#o-gen/.gi+gnore
.gitignore에�적용된�패턴에�해당되는�파일은�
Git을�통해�추적하지�않습니다.�
.gitignore
07�스테이징�영역에�.gitignore�파일�추가��git�add�
Working Directory
.gitignore
Staging Area
Local Git Repository Branch Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git add [파일명|패턴]�으로�스테이징�영역에�추가�
.gitignore
$ git add .gitignore
git add –A 옵션을�주면�모든�변경된�파일�추가�
08�대망의�첫�커밋!��git�commit�
Working Directory
Staging Area
.gitignore
Local Git Repository Branch1. add .gitignore
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git commit –m “커밋�메시지”로�메시지와�함께�커밋�
.gitignore
$ git commit –m “add .gitignore”[master (root-commit) 8fe2b9e] add .gitignore 1 file changed, 2 insertions(+) create mode 100644 .gitignore
Git은�커밋�시�메시지가�꼭�포함되어야�하며,�-m�“메시지”�옵션이�생략되면�기본으로�설정된�vim�에디터로�커밋�메시지를�입력할�수�있습니다.�
gg�
1�
master�
09�파일�상태�확인��git�status�
Working Directory
Staging Area
.gitignore
Local Git Repository Branch1. add .gitignore
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git status 명령으로�파일의�상태�확인�
.gitignore
$ git statusOn branch master Untracked files: (use "git add <file>..." to include in what will be committed) README.md make src/ nothing added to commit but untracked files present (use "git add" to track)
빨간색은�untracked�상태�녹색은�unstaged�상태�
gg
1�
master�
10�커밋�로그�확인��git�log�
Working Directory
Staging Area
.gitignore
Local Git Repository Branch1. add .gitignore
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git log�명령으로�커밋�로그�확인�
.gitignore
$ git logcommit 8fe2b9ed4f00e242f86fb32734bd7c9a0a861b3eAuthor: Junyoung Lee <[email protected]> Date: Fri May 13 21:35:03 2016 +0000 add .gitignore
gg
1�
master�
순서대로�커밋�ID,�커밋�작성자,�날짜,�커밋�메시지�출력�
11�나머지�모든�파일�스테이징�영역에�추가�
Working Directory
README.mdmakesrc/project/LottoGenerator
Staging Area
.gitignore
Local Git Repository Branch1. add .gitignore
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git add로�추가하고 git status로�확인�
.gitignore
$ git add . $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: README.md new file: make new file: src/project/LottoGenerator.java
gg
1�
master�
- git add�명령�시�파일�이름�대신�.�을�입력하면�현재�디렉토리�하위의�모든�파일을�추가합니다.�
- git은�빈�디렉토리는�추적하지�않습니다.�
12�두�번째�커밋!��
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
이번에는�–m 옵션을�생략해�봅시다.�
.gitignore initialize # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # new file: README.md# new file: make # new file: src/project/LottoGenerator.java
$ git commit
<vim�에디터>�
:wq로�저장하고�나오면�vim에서�작성한�메시지로�커밋됩니다.�
gg
1�
gg
2�
master�
13�랜덤�번호�생성�메서드�추가��복붙하세요!�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
LottoGenerator.java�파일을�수정해�봅시다.�
.gitignore
package project;
import java.util.Random;import java.util.Arrays;
public class LottoGenerator {private Random random = new Random(System.nanoTime());
public int[] generate() {int[] result = new int[6];
for(int i = 0; i < 6; i++) {result[i] = random.nextInt(45);
}
return result;}
public static void main(String[] args) {int[] result = new LottoGenerator().generate();System.out.println(Arrays.toString(result));
}}
src/project/Lo#oGenerator.java
gg
1�
master�
gg
2�
14�구름�IDE에서�빌드하고�실행해보기�-�빌드�
15�구름�IDE에서�빌드하고�실행해보기��빌드�결과�확인�
16�구름�IDE에서�빌드하고�실행해보기��실행�
17�구름�IDE에서�빌드하고�실행해보기��실행�결과�
18�수정된�내용을�커밋해�봅시다.�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
먼저�git add�하고,�
.gitignore
gg
1�
master�
gg
2�
$ git add src/project/LottoGenerator.java
$ git commit -m "add a generate method" [master c7dd9a7] add generate method 1 file changed, 17 insertions(+), 7 deletions(-)
git commit!�
gg
3�
19�버그�발견!��생성되는�번호의�범위�수정�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
generate()�메서드에�심각한�결함이�있습니다.이를�수정하기�위해�branch를�활용해�보겠습니다.�
.gitignore
$ git checkout –b hotfix1Switched to a new branch ‘hotfix1’
파일을�수정하기�전에�git checkout 명령에�–b�옵션을더해�‘hotfix1’�브랜치를�생성하면서�체크아웃�합니다.
checkout은�브랜치나�특정�버전을�선택하여워킹�디렉토리로�가져옵니다.
이제�hotfix1�브랜치는 master와�같은�곳을�가리킵니다.
gg
1�
master�
gg
2�
gg
3�
hotfix1�
20�브랜치�확인��git�branch�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git branch�명령을�이용해�브랜치�목록과현재�브랜치를�확인할�수�있습니다.�
.gitignore
$ git branch* hotfix1 master
브랜치�목록이�출력되며, hotfix1을�생성하면서체크아웃�했으므로 hotfix1�앞에�*가�있는�것을확인할�수�있습니다.
gg
1�
master�
gg
2�
gg
3�
hotfix1�
21�이제�버그를�잡아�봅시다.�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
LottoGenerator 클래스에서�잘못된�부분을�수정합니다.�
.gitignore
…
public int[] generate() {int[] result = new int[6];
for(int i = 0; i < 6; i++) {
result[i] = random.nextInt(45) + 1;}
return result;}
…
src/project/Lo#oGenerator.java
gg
1�
master�
gg
2�
gg
3�
hotfix1�
22�변경된�내용�비교하기��git�diff�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git diff�명령을�이용해�변경된�내용을�확인할�수�있습니다.�
.gitignore
$ git diffdiff --git a/src/project/LottoGenerator.java b/src/project/LottoGenerator.java index 8001224..0177b1c 100644 --- a/src/project/LottoGenerator.java +++ b/src/project/LottoGenerator.java @@ -10,12 +10,10 @@ public class LottoGenerator { int[] result = new int[6]; for(int i = 0; i < 6; i++) { - result[i] = random.nextInt(45); + result[i] = random.nextInt(45) + 1; } ...
삭제된�라인은�빨간색,�추가된�라인은�녹색으로�표시됩니다.또한�설정을�통해 diff�툴을�변경할�수�있습니다.�
gg
1�
master�
gg
2�
gg
3�
hotfix1�
23�변경된�파일을�스테이징�영역에�추가하고�상태�확인�
Working Directory
src/project/LottoGenerator.java
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git add로�추가하고, git status로�상태�확인�
.gitignore
gg
1�
master�
gg
2�
gg
3�
hotfix1�
$ git add –A$ git statusOn branch hotfix1 Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: src/project/LottoGenerator.java
24�커밋~!�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
git commit으로�커밋!�
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
hotfix1�
$ git commit –m “fix range of generated numbers”[hotfix1 d09e74b] fix range of generated numbers 1 file changed, 1 insertion(+), 3 deletions(-)
git log로�커밋�로그�확인!�$ git log --pretty=onelined09e74b6545fe82476873ddb6eb979ab06a192c9 fix range of generated numbers f55b9286611b1b95152447b11a1e1f46261201e2 ignore 수정 c7dd9a710bbb5accb6365b007ed1ac5a933ba2c2 add generate method 79243db381d97378f5701d56c4145fbac899eac7 initialize 8fe2b9ed4f00e242f86fb32734bd7c9a0a861b3e add .gitignore
git log에�다양한�옵션을�적용하여�출력할�수�있습니다.�
25�각�브랜치의�워킹�디렉토리�비교�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
현재�hotfix1의�LottoGenerator�클래스는�수정된�상태입니다.�master�브랜치로�체크아웃하여�LottoGenerator�클래스를�비교해�보겠습니다.�
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
hotfix1�
$ git checkout masterSwitched to branch ‘master’
$ cat src/project/LottoGenerator.java...result[i] = random.nextInt(45); ...
hotfix1�브랜치에서�변경했던�부분이�변경�하기�전의�코드임을�확인할�수�있습니다.�브랜치가�변경되면�워킹�디렉토리의�파일도�통째로�변경됩니다.�
26�브랜치�합치기��git�merge�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1� master�
gg
2�
gg
3�
gg
4�
hotfix1�
git merge 명령어로�브랜치를�합칠�수�있습니다.먼저�머지를�적용할�브랜치로�이동합니다.�$ git checkout masterSwitched to branch ‘master’
git merge�실행�
$ git merge hotfix1Updating f55b928..d09e74b Fast-forward src/project/LottoGenerator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
git merge [브랜치]�명령을�실행하면현재�브랜치에�[브랜치]를�가져와�합치게�됩니다.�
27�브랜치�삭제�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
hotfix1�브랜치는�더이상�사용하지�않으므로git branch –d [브랜치]�명령으로�브랜치를�삭제합니다.�
$ git branch –d hotfix1Deleted branch hotfix1 (was d09e74b).
git branch�명령으로�브랜치�확인�
$ git branch* master
28�원격�저장소(Repository)�생성�(1)�
29�원격�저장소(Repository)�생성�(2)�
30�원격�저장소(Repository)�생성�(3)�
31�원격�저장소�설정��git�remote�add�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
git remote add�명령어로�원격�저장소를�설정합니다.�
$ git remote add origin [GitHub 저장소 주소]$ git remote -v origin https://github.com/nnoco/git-github-nnoco (fetch) origin https://github.com/nnoco/git-github-nnoco (push)
git remote -v 명령으로�원격�저장소가�등록된�것을확인할�수�있습니다.�
32�원격�저장소에�푸시(Push)��git�push�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
git push [Remote] [Branch]�명령으로원격�저장소에�로컬�저장소의�파일을�업로드�합니다.�
$ git push origin master Username for 'https://github.com': nnoco Password for 'https://[email protected]': Counting objects: 27, done. Delta compression using up to 16 threads. Compressing objects: 100% (16/16), done. Writing objects: 100% (27/27), 2.87 KiB | 0 bytes/s, done. Total 27 (delta 4), reused 0 (delta 0) To https://github.com/nnoco/git-github-nnoco * [new branch] master -> master
인증을�위해�아이디와�비밀번호를�입력하면�푸시�과정이진행되는�것을�확인할�수�있습니다.�
33�GitHub에서�푸시�결과�확인�
34�GitHub에서�커밋�로그�확인�
35�버그�발견!��중복�생성된�번호�확인하기�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
아까랑�똑같죠?git checkout –b [브랜치]로�브랜치�생성&체크아웃그리고�LottoGenerator�클래스의�버그�수정�
$ git checkout -b hotfix2 Switched to a new branch 'hotfix2’
package project;
import java.util.Random;
import java.util.Arrays;import java.util.Set;
import java.util.HashSet;
public class LottoGenerator {
private Random random = new Random(System.nanoTime());
public int[] generate() {
int[] result = new int[6];int index = 0;
Set<Integer> generated = new HashSet<>();
while(generated.size() < 6) {int num = random.nextInt(45) + 1;
// 생성된 목록에 포함되어 있지 않으면 추가if(!contains(generated, num)) {
result[index++] = num;generated.add(num);
}
}
return result;}
boolean contains(Set<Integer> generated, int num) {return generated.contains(num);
}
public static void main(String[] args) {
int[] result = new LottoGenerator().generate();System.out.println(Arrays.toString(result));
}}
src/project/Lo#oGenerator.java
이�코드도�복붙하세요~
hotfix2�
36�add와�commit을�한�번에�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. fix to remove duplicate numbers
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
사실�git add는�조금�무의미하게�반복될�때가�있어서add와�commit을�한번에�할�수�있는�방법이�있습니다.git commit�명령�실행�시�–a�옵션을�더해줍니다.�
$ git commit –am “fix to remove duplicate numbers”[hotfix2 cae4f5b] fix to remove duplicate numbers 1 file changed, 16 insertions(+), 2 deletions(-)
-a�옵션은�파일의�상태가�tracked인�경우에�한해서�적용되며,스테이징�영역에�파일을�추가하는�작업을��건너뛸�수�있습니다.
gg
5�hotfix2�
37�충돌�만들기�(1)�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. [hotfix2] fix to remove duplicate
numbers6. [hotfix2] modify comment
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
Git은�문제가�없는�경우�자동으로�병합이�되지만, 서로�다른�브랜치에서�같은�부분이�수정된�경우에는충돌(Conflict)이�발생할�수�있습니다.임의로�충돌이�나는�상황을�만들고,�이를�수정해보겠습니다.
LottoGenerator의�소스코드를�복사(Ctrl+C)�한�후hotfix2�브랜치에서�주석�부분을�조금�수정합니다.
gg
5�
hotfix2�
// 생성된 목록에 포함되어 있지 않으면 추가-> //// 생성된 목록에 포함되어 있지 않으면 추가 //
$ git commit –am “modify comment”[hotfix2 cae4f5b] fix to remove duplicate numbers 1 file changed, 1 insertions(+), 1 deletions(-)
gg
6�
38�충돌�만들기�(2)�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. [master] modify comment
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
다음으로�master�브랜치로�체크아웃�한�후금방�복사한�소스코드를�그대로�붙여넣고,역시�주석�부분을�아래와�같이�수정합니다.
gg
5�
hotfix2�
// 생성된 목록에 포함되어 있지 않으면 추가-> /* 생성된 목록에 포함되어 있지 않으면 추가 */
$ git commit –am “modify comment”[hotfix2 cae4f5b] fix to remove duplicate numbers 1 file changed, 1 insertions(+), 1 deletions(-)
gg
6�
$ git checkout masterSwitched to branch ‘master’
gg
5�
39�충돌�만들기�(3)�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. [master] modify comment
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
이제 git merge 명령으로�브랜치를�병합합니다.
gg
5�
hotfix2�
gg
6�
$ git merge hotfix2 Auto-merging src/project/LottoGenerator.java CONFLICT (content): Merge conflict in src/project/LottoGenerator.java Automatic merge failed; fix conflicts and then commit the result.
gg
5�
LottoGenerator.java�파일에�충돌이�있어서Git이�자동으로�브랜치를�병합하는데�실패했다는�메시지가�표시됩니다.
40�충돌�해결하기�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. [master] modify comment6. [master] resolve merge conflict
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
편집기에서�LottoGenerator.java�파일을�엽니다.
<<<<<<<HEAD /*생성된 목록에 포함되어 있지 않으면 추가.*/
======= ////생성된 목록에 포함되어 있지 않으면 추가 //
>>>>>>>ho@ix2
주석을�수정한�부분에�기호와�함께�브랜치�이름이�있습니다.HEAD�부분이�master�브랜치에서�수정한�내용입니다.
둘�중�보존할�코드를�두고�나머지�라인을�지우고�저장합니다.
/*생성된 목록에 포함되어 있지 않으면 추가.*/
$ git commit –am “resolve merge conflict”[master 01aa0d4] resolve merge conflict
gg
1�
master�
gg
2�
gg
3�
gg
4�
gg
5�
hotfix2�
gg
6�
gg
5�
gg
6�
41�커밋�로그�확인�&�원격�저장소에�Push�
Working Directory
Staging Area
.gitignoremakeREADME.mdsrc/project/LottoGenerator.java
Local Git Repository Branch1. add .gitignore2. initialize3. add a generate method4. fix range of generated numbers5. [master] modify comment6. [master] resolve merge conflict
Commit Logs
lotto-genbinsrc
project
LottoGenerator.java
README.md
make
.gitignore
gg
1�
master�
gg
2�
gg
3�
gg
4�
병합이�어떤�모습으로�되었는지�git log로�볼�수�있습니다.
gg
5�
hotfix2�
gg
6�
gg
5�
$ git log --pretty=oneline –graph* d6103389f8bdb2b5f3dcd704951153979c032c35 resolve merge conflict |\ | * 29958dfac599fd0041dbc572ec5b78e865d185fc modify comment | * 3377035191476e9e1cf5b4775e1de06b87777c37 fix to remove duplicate number ...
gg
6�
지금까지의�커밋을�원격�저장소로�푸시합니다.$ git push origin masterUsername for 'https://github.com': nnoco Password for 'https://[email protected]': ...
GitHub�살펴보기�
Filmtocat�-�https://octodex.github.com/filmtocat�
01�프로필�페이지�
02�프로필�수정�
03�저장소�살펴보기�
04�Issues�
05�이슈�작성�
06�작성된�이슈�확인과�댓글�
07�Pull�Request�
08�Wiki�
09�위키�작성�
10�위키�확인�
11�Pulse�
12�Graph�
13�Settings�
14�Organization�생성하기�(1)�
15�Organization�생성하기�(2)�
16�Organization�생성하기�(3)�
17�Organization�생성하기�(4)�
18�Organization�생성하기�(5)�
19�Pull�Request�보내기�(1)�
GitHub�
원본�원격�저장소�nnoco/git-github-nnoco�
�Fork�원격�저장소�devignner/git-github-nnoco�
Fork�
Pull�Request�
로컬�저장소�
Push�
Clone/Pull�
1
2
3
4
Pull�Request�보내기�과정�
20�Pull�Request�보내기�(2)�
21�Pull�Request�보내기�(3)�
22�Pull�Request�보내기�(4)�
23�Pull�Request�보내기�(5)�
$ git clone https://github.com/ma-non-troppo/git-github-nnoco.git Cloning into 'git-github-nnoco'... remote: Counting objects: 43, done. remote: Compressing objects: 100% (21/21), done. remote: Total 43 (delta 10), reused 43 (delta 10), pack-reused 0 Unpacking objects: 100% (43/43), done. Checking connectivity... done.
원격�저장소의�주소를�복사하여�git clone [URL]�명령을�실행합니다�
$ ls git-github-nnoco lotto-gen$ cd git-github-nnoco$ pwd/workspace/git-github-nnoco
ls 명령어를�실행하면�git-github-[아이디]�디렉토리가�생성된�것을�확인하실�수�있습니다.�cd�명령어로�해당�디렉토리로�들어갑니다.�
$ cd /workspace
구름�IDE의�터미널에서�/workspace 디렉토리로�이동합니다.�
24�Pull�Request�보내기�(6)�
vim�에디터로�주석�부분을�단행�주석으로�수정합니다.�
/*생성된 목록에 포함되어 있지 않으면 추가.*/->// 생성된 목록에 포함되어 있지 않으면 추가.
$ git checkout –b topicSwitched to a new branch ‘topic’
코드�수정을�위해�topic�브랜치를�만들고�체크아웃�합니다.�
$ vim src/project/LottoGenerator.java
수정�사항을�커밋합니다.�$ git commit –am “modify comment”[topic 10cdbab] modify comment 1 file changed, 1 insertion(+), 1 deletion(-)
그리고�원격�저장소로�Push!�$ git push origin topic Username for 'https://github.com': ma-non-troppo Password for 'https://[email protected]': Counting objects: 10, done. ...
25�Pull�Request�보내기�(7)�
26�Pull�Request�보내기�(8)�
27�Pull�Request�보내기�(9)�
28�Pull�Request�받기�(1)�
GitHub�
원본�원격�저장소�nnoco/git-github-nnoco�
�Fork�원격�저장소�devignner/git-github-nnoco�
Merge�Pull�Request�
Pull�Request�
로컬�저장소�
Push�(직접�merge한�경우)�
Fetch�
4
24`
1
Pull�Request�받기�과정�
merge�
3
29�Pull�Request�받기�(2)�
30�Pull�Request�받기�(3)�
31�Pull�Request�받기�(4)�
$ git pull origin master From https://github.com/nnoco/git-github-nnoco * branch master -> FETCH_HEAD Already up-to-date.
git pull�명령어로�원격�저장소의�변경�사항을�가져옵니다.�
$ git checkout -b pr Switched to a new branch 'pr'
Pull Request의�확인을�위한�브랜치�pr을�생성하고�체크아웃합니다.�
$ cd /workspace/lotto-gen
처음�실습했던�lotto-gen�디렉토리로�이동합니다.�
$ git remote add [보낸사람_사용자명] [보낸 사람의 Git_URL]Switched to a new branch 'pr'
Pull Request를�보낸�사용자의�원격�저장소를�추가합니다.�
$ git fetch [보낸사람_사용자명]remote: Counting objects: 5, done. remote: Compressing objects: 100% (1/1), done. remote: Total 5 (delta 2), reused 5 (delta 2), pack-reused 0 ...
추가한�원격�저장소의�변경사항을�fetch�합니다.�
32�Pull�Request�받기�(5)�
$ git merge [보낸사람_사용자명]/topic
Pull Request를�확인하기�위해�pr�브랜치로�병합합니다.�
이상없이�병합이�되고,�기능상의�문제가�없음이�확인되면�pr�브랜치를�제거하기�위해master�브랜치로�체크아웃합니다.�$ git checkout master Switched to branch 'master'
pr�브랜치를�제거합니다.�$ git branch –d prDeleted branch pr (was d610338).
33�Pull�Request�받기�(6)�
34�Pull�Request�받기�(7)�
35�Pull�Request�받기�(8)�
맛깔나게�활용하는�
GIT과�GITHUB�
Adventure�Cat�-�https://octodex.github.com/adventure-cat�
01�GitHub�페이지�활용하기�(1)�
02�GitHub�페이지�활용하기�(2)�
03�GitHub�페이지�활용하기�(3)�
04�GitHub�페이지�활용하기�(4)�
05�GitHub�페이지�활용하기�(5)�
06�GitHub�페이지�활용하기�(6)�
07�GitHub�페이지�활용하기�(7)�
08�Gist�(1)�
09�Gist�(2)�
10�Gist�(3)�
11�Gist�(4)�
12�GitBook�(1)�
13�GitBook�(2)�
GIT,�좀�더�깊게�보기�
20%�Cooler�Octocat�-�https://octodex.github.com/twenty-percent-cooler-octocat�
01�.git�디렉토리�살펴보기�
COMMIT_EDITMSG�
HEAD�
ORIG_HEAD��
branches�
config�
description�
hooks�
index�
info�
logs�
objects�
refs�
마지막�커밋�메시지�
현재�체크아웃한�브랜치를�가리키는�포인터�
origin의�헤드를�가리키는�포인터�
예전�버전에�사용한�브랜치�정보�
해당�프로젝트에만�해당되는�설정�
GitWeb�등에서�사용하는�프로젝트�정보�
클라이언트�훅(Hook)이나�서버�훅�스크립트�위치�
스테이징�영역의�정보를�저장�
.gitignore와�같은�역할을�하며�버전관리는�되지�않음�
커밋�로그�정보�
모든�정보를�저장하는�데이터베이스�
커밋�객체의�참조�정보(포인터)�저장�
02�Git�Branch�전략�
h#p://nvie.com/posts/a-successful-git-branching-model/
1. 개발�브랜치(Develop)에서�작업�브랜치(feature)를�
생성해서�기능을�구현하거나�수정�
2. 작업�브랜치(feature)에서�코드를�모두�작성하면,�개발�
브랜치(develop)에�merge�
3. 1번과�2번을�반복하면서�배포할�수�있는�수준까지�개
발�
4. 배포를�위한�릴리즈�브랜치(release)를�생성�
5. 배포�작업이�끝나면�master�브랜치에�merge하고,�버
전�태그를�붙여서�배포�
6. 배포하고�있는�소프트웨어에�버그가�있는�경우에는�해
당�버전을�기반으로�수정(hotfixes�브랜치)�
- master�브랜치는�항상�안정된�버전(배포�가능한�버전)�
- 브랜치가�많아서�복잡할�수�있음�
- git-flow�툴을�설치하여�효율적으로�관리�가능�
- 어떤�브랜치가�서로�상호작용�하는지�이해하고�있어야�
함�
�
03�Commit�Message의�활용�(1)�
커밋�메시지는�‘잘’�작성해야�합니다.��커밋�가이드라인�
• 공백�문자를�깨끗이�제거한다.�
• 최대한�수정�사항을�하나의�주제로�요약한다.�
• 여러�가지�이슈에�대한�수정사항을�하나의�커밋에�담지�않는다.�
• 적절한�메시지를�작성한다�:�반드시�좋은�커밋�메시지를�담는다.�
• 같은�파일의�다른�부분을�수정하는�경우에는�git�add�-patch�명령을�이용한
다.�
• 한�부분씩�나누어�Stage�영역에�저장한다.�
04�Commit�Message의�활용�(2)�
커밋�메시지�양식�
• 첫�줄에는�50자(영문,�한글�25자)�로�간략히�요약해서�작성한다.�
• 두�번째�줄을�비우고�세�번째�줄에�자세하게�설명글을�작성한다.�
(개발동기,�구현�상황,�제약조건/상황�등)�
• 글은�현재형을�사용한다.�
• 추가�내용은�한�줄�띄우고�시작한다.�
• 커밋�메시지가�잘�쓰여진�프로젝트를�받아서�git�log�--no-merges�명령으로�살펴
본다.�
RedirectusertotherequestedpageaOerloginh#ps://trello.com/path/to/relevant/cardUserswerebeingredirectedtothehomepageaOerlogin,whichislessusefulthanredirec+ngtothepagetheyhadoriginallyrequestedbeforebeingredirectedtotheloginform.*Storerequestedpathinasessionvariable*Redirecttothestoredloca+onaOersuccessfullyloggingintheuser
커밋�메시지�영문�예시�
05�Commit�Message의�활용�(3)�
GitHub의�커밋�메시지�활용�
• 관련�이슈�링크�
커밋�메시지에�#이슈번호�를�쓰면�해당�이슈�링크가�자동으로�생성�
• 이슈�닫기(Close)�
fix�#이슈번호,�fixes�#이슈번호,�fixed�#이슈번호,�close�#이슈번호,�resolve�#이슈번호�등�
Open�상태인�이슈는�커밋�메시지로�인해�자동으로�Close�됨�
• 알림(Notification)�보내기�
@사용자이름�또는�@조직이름을�쓰면�해당�사용자나�조직�멤버에게�알림�전송�
@조직이름�팀이름을�쓰면�해당�팀에게�알림�전송�
더�볼�수�있는�곳들�
Professortocat_v2�-�https://octodex.github.com/Professortocat_v2�
01�http://learngitbranching.js.org�
02�https://try.github.com��
03�https://www.codecademy.com/learn/learn-git��
04�책과�사이트�
• 생활코딩�Git�코스�-�https://opentutorials.org/course/1492�
• Pro�git(Web)�-�https://git-scm.com/book/ko/v2�
• Git�간편�안내서�-�http://rogerdudler.github.io/git-guide/index.ko.html�
• A�Visual�Git�Reference�-�http://marklodato.github.io/visual-git-guide/index-ko.html�
Pro�Git(종이책)�스캇�샤콘�저,�박창우,�이성환,�최용재�옮김�
소셜�코딩으로�이끄는�GitHub�실천�기술�오오츠카�히로키�저,�윤인성�옮김�
감사합니다!�
Mountietocat�-�https://octodex.github.com/mountietocat�
이준영���Junyoung�Lee�http://nnoco.tistory.com�
[email protected]�https://www.facebook.com/nnoco�
�