O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Basic git-commands

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
git-basic-commands
git-basic-commands
Carregando em…3
×

Confira estes a seguir

1 de 100 Anúncio

Basic git-commands

Baixar para ler offline

본 자료는 14.12.20 KGUG(Korea Git User Group) 주최 대학생 대상 Git 교육인

“Getting Started with git” 에서 발표된 “Git Basic Commands” 의 발표내용을 담고 있습니다.

본 자료는 크리에이티브 커먼즈 저작자표시-비영리-변경금지(CC BY-NC-ND) 3.0 Unported 라이선스에 따라 이용할 수 있습니다.

본 자료에 사용 된 이미지들은 Creative Common License 를 따르며 이미지 출처는 해당 이미지 하단에 기제 되어 있습니다.

본 자료는 14.12.20 KGUG(Korea Git User Group) 주최 대학생 대상 Git 교육인

“Getting Started with git” 에서 발표된 “Git Basic Commands” 의 발표내용을 담고 있습니다.

본 자료는 크리에이티브 커먼즈 저작자표시-비영리-변경금지(CC BY-NC-ND) 3.0 Unported 라이선스에 따라 이용할 수 있습니다.

본 자료에 사용 된 이미지들은 Creative Common License 를 따르며 이미지 출처는 해당 이미지 하단에 기제 되어 있습니다.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Quem viu também gostou (20)

Anúncio

Semelhante a Basic git-commands (20)

Mais recentes (20)

Anúncio

Basic git-commands

  1. 1. Basic Commands insanehong@KGUG 2014. 12. 20
  2. 2. NAVER / NAVER LABS twitter: @insanehong email : insanehong@gmail.com http://about.me/insanehong insanehong.talk.start(“Hi! Bro!”)
  3. 3. 이시간에 다루지 않을 것들
  4. 4. https://www.flickr.com/photos/miguelpdl/4994396370
  5. 5. 이시간에 전달하려고 하는 것들
  6. 6. 기본적인 사용법 & 개념 내부 동작 원리
  7. 7. 주의! 이 교육은 간접 광고를 포함하고 있지 않습니다. http://www.dailycal.org/2013/11/21/everybody-macbook/
  8. 8. Why do programmers use or recommend macs or linux? http://www.dailycal.org/2013/11/21/everybody-macbook/ 주의! 이 교육은 간접 광고를 포함하고 있지 않습니다.
  9. 9. & CLIGUI Recommend
  10. 10. NAVER give up!! e 이 교육은 간접 광고를 절대 포함하고 있지 않습니다. photo by https://www.flickr.com/photos/slworking/
  11. 11. Try git better, together
  12. 12. 우리 모두는 A사 입사를 위해 퀴즈를 풀어 제출해야 합니다.
  13. 13. 채용 퀴즈 “같은 문자가 연속적으로 반복되는 경우에 그 반복 횟수를 표시하여 문자열을 압축하기” 제출 방법 • recruiting@a.com 으로 github url 제출 • 첨부파일로는 받지 않습니다.
  14. 14. Great a Git repository
  15. 15. git init “This command creates an empty git repository” - https://www.kernel.org/pub/software/scm/git/docs/git-init.html -
  16. 16. • 현재 디렉토리를 git 저장소로 만들 때 $> git init • 새로운 디렉토리를 만들때 $> git init <directory>
  17. 17. /workspace $> git init git-study && cd git-study Initialized empty Git repository /workspace/git-study/.git/
  18. 18. /git-study .git└─
  19. 19. /git-study .git└─
  20. 20. Repository Structure
  21. 21. Working tree index (Staging area) object database Working area Cache storage Storage
  22. 22. Working tree index (Staging area) object database git add git commit
  23. 23. 여기서 잠깐!
  24. 24. What is commit?
  25. 25. “In computer science and data management, a commit is the making of a set of tentative changes permanent.” - http://en.wikipedia.org/wiki/Commit_(data_management) -
  26. 26. “특정 시점에 대한 스냅샷 혹은 상태”
  27. 27. Git 사용한다는 것?
  28. 28. Git 으로 commit 을 다루는것!
  29. 29. Untracked Staged Committed Modified Tracked git add git commit edit file git add file
  30. 30. Be committed to doing
  31. 31. /git-study .git├─ compress.js└─ │
  32. 32. http://git.io/Tq59Hw
  33. 33. Working tree index (Staging area) object database git add git commit
  34. 34. git add “This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit” - https://www.kernel.org/pub/software/scm/git/docs/git-add.html -
  35. 35. “working directory 에서 변경되거나 추가된 파일들 중에서 커밋에 포함될 파일들을 등록해 놓는 것”
  36. 36. • 특정 파일들만을 지정 $> git add <file1> <file2> • 변경되거나 추가된 모든 파일을 다룰때 $> git add -a
  37. 37. 여기서 잠깐 Two!
  38. 38. 변경 파일이 많거나 어떤 파일이 수정 되었는지 모를때는?
  39. 39. git status “Displays paths that have differences between the index file and the current HEAD commit, and paths in the working tree that are not tracked by git” - https://www.kernel.org/pub/software/scm/git/docs/git-status.html -
  40. 40. “Woking directory 의 상태를 보여준다. ”
  41. 41. • 자세한 내용을 확인 할때 $> git status • 파일들의 변경 상태만 확인 할때 $> git status -s
  42. 42. $> git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) compress.js nothing added to commit but untracked files present (use "git add" to track) $> git status -s ?? compress.js
  43. 43. /git-study .git├─ compress.js└─ │ $> git add compress.js $> git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: compress.js $> git status -s A compress.js
  44. 44. Working tree index (Staging area) object database git add git commit
  45. 45. git commit “Stores the current contents of the index in a new commit along with a log message from the user describing the changes.” - https://www.kernel.org/pub/software/scm/git/docs/git-commit.html -
  46. 46. /git-study .git├─ compress.js└─ │ $> git commit -m “문제풀이 완료” [master (root-commit) 5525f5f] 문제풀이 완료 1 file changed, 28 insertions(+) create mode 100644 compress.js $> git status On branch master nothing to commit, working directory clean 5525f5f 문제풀이 완료
  47. 47. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); Untracked
  48. 48. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); blob function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; 81b90e8 Staged
  49. 49. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); blob function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; tree 81b90e8 3cfa7a2 compress.js 81b90e8 commit 5525f5f tree 3cfa7a2 author insnae<insnae@mail> 1330482646 +0900 commiter insnae<insnae@mail> 1330482646 +0900 문제풀이 완료 Commited
  50. 50. 자 이제 코드를 제출하면 되나요?
  51. 51. $> node compress hello world, hello git > hel2o world, hel2o git helloooooooo > hel2o 제가 한번 실행해 보겠습니다!
  52. 52. https://www.flickr.com/photos/slworking/8739080572 이상한 점을 찾으셨나요?
  53. 53. “helloooooooo”> hel2o currently
  54. 54. “helloooooooo”> hel2o8 Goals
  55. 55. 8 if( str.charAt(i) === prev ) { 9 repeat++; 10 if ( i === str.length -1) result+=repeat; 11 } else { Solution
  56. 56. 8 if( str.charAt(i) === prev ) { 9 repeat++; 10 if ( i === str.length - 1 ) result += repeat; 11 } else { • 버그 수정후 “버그 수정” 이란 메세지로 커밋 • header 추가 후 커밋 “헤더 추가” 란 메세지로 커밋 1 /* 2 Author insanehong <insanehong@gmail.com> 3 LICENSE under BSD 4 */
  57. 57. git diff “Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk..” - https://www.kernel.org/pub/software/scm/git/docs/git-diff.html -
  58. 58. • working directory 와 index 를 비교 $> git diff • 커밋 간 차이점 을 비교 $> git diff <commitA>..<commitB> • index 와 HEAD를 비교 $> git diff --staged
  59. 59. /git-study .git├─ compress.js└─ │ $> git diff diff --git a/compress.js b/compress.js index 81b90e8..46c3d6e 100644 --- a/compress.js +++ b/compress.js @@ -7,6 +7,7 @@ function compress(str) { if( str.charAt(i) === prev ) { repeat++; + if ( i === str.length -1) result+=repeat; } else { if (repeat > 1) result+=repeat; result+=str.charAt(i); 5525f5f 문제풀이 완료
  60. 60. /git-study .git├─ compress.js└─ │ $> git add compress.js $> git status -s M compress.js $> git commit -m “버그수정” [master f5cd615] 버그 수정 1 file changed, 1 insertion(+) 5525f5f 문제풀이 완료 f5cd615 버그 수정
  61. 61. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); blob function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; tree 81b90e8 3cfa7a2 compress.js 81b90e8 commit 5525f5f tree 3cfa7a2 author insnae<insnae@mail> 1330482646 +0900 commiter insnae<insnae@mail> 1330482646 +0900 문제풀이 완료 Modified
  62. 62. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); blob if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } e b3bddc commit 81b90e8 tree 3cfa7a2 blob 81b90e8 Staged
  63. 63. compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); compress.js function compress(str) { var repeat = 1; var result = str.charAt(0); var prev = result; for( var i =1; i < str.length; i++ ) { if( str.charAt(i) === prev ) { repeat++; if ( i === str.length - 1 ) result += repeat; } else { if (repeat > 1) result += repeat; result += str.charAt(i); repeat = 1; } prev = str.charAt(i); } console.log(str, ' > ', result); } var test1 = "hello world, hello git"; var test2 = "helloooooooo"; compress(test1); compress(test2); commit 81b90e8 tree 3cfa7a2 blob 81b90e8 commit f5cd61 tree 1b3d8b blob b3bddc Commited
  64. 64. /git-study .git├─ compress.js└─ │ $> git add compress.js $> git status -s M compress.js $> git commit -m “헤더 추가” [master b6f9dc3] 헤더 추가 1 file changed, 4 insertions(+) 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가
  65. 65. Commit inspection
  66. 66. git log “Shows the commit logs.” - https://www.kernel.org/pub/software/scm/git/docs/git-log.html -
  67. 67. • 현재 저장소의 시간순 커밋 히스토리 
 $> git log • diff 를 함께 보기 $> git log —p • 커밋 메세지 조회 $> git log --grep <검색어>
  68. 68. $> git log commit b6f9dc38625689032f6172bef905ae0a2aeebaa0 Author: insanehong <insanehong@gmail.com> Date: Sat Dec 20 00:00:47 2014 +0900 헤더 추가 commit f5cd615c4643dce328fe56e291a16c43ef9c3a77 Author: insanehong <insanehong@gmail.com> Date: Fri Dec 19 23:54:00 2014 +0900 버그 수정 commit 5525f5f0b8945c342a489ab1ff72469e5745a33e Author: insanehong <insanehong@gmail.com> Date: Fri Dec 19 23:18:42 2014 +0900 문제풀이 완료 $> git log --grep "버그" commit f5cd615c4643dce328fe56e291a16c43ef9c3a77 Author: insanehong <insanehong@gmail.com> Date: Fri Dec 19 23:54:00 2014 +0900 버그 수정 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가
  69. 69. git show “Shows one or more objects (blobs, trees, tags and commits)” - https://www.kernel.org/pub/software/scm/git/docs/git-show.html -
  70. 70. $> git show commit b6f9dc38625689032f6172bef905ae0a2aeebaa0 Author: insanehong <insanehong@gmail.com> Date: Sat Dec 20 00:00:47 2014 +0900 헤더 추가 diff --git a/compress.js b/compress.js index 46c3d6e..cfdcf63 100644 --- a/compress.js +++ b/compress.js @@ -1,3 +1,7 @@ +/* +Author insanehong <insanehong@gmail.com> +*/ + function compress(str) { var repeat = 1; var result = str.charAt(0); 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가
  71. 71. Push to remote repository
  72. 72. bare None-bare None-bare None-bare
  73. 73. Github Local repo Local repo Local repo
  74. 74. git remote “Manage the set of repositories ("remotes") whose branches you track.” - https://www.kernel.org/pub/software/scm/git/docs/git-remote.html -
  75. 75. • 원격 저장소 추가 
 $> git remote add <alias> <url> • 원격 저장소 alias 변경 $> git remote rename <old> <new> • 원격 저장소 url 변경 $> git remote set-url <alias> <url> • 원격 저장소 확인 $> git remote -v
  76. 76. $> git remote add origin git@github.com:insanehong/git-study.git $> git remote -v origin https://github.com/insanehong/git-repo.git (fetch) origin https://github.com/insanehong/git-repo.git (push) .git config└─
  77. 77. git push “Updates remote refs using local refs, while sending objects necessary to complete the given refs.” - https://www.kernel.org/pub/software/scm/git/docs/git-push.html -
  78. 78. $> git push origin master Counting objects: 9, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (9/9), 965 bytes | 0 bytes/s, done. Total 9 (delta 2), reused 0 (delta 0) To git@github.com:insanehong/git-study.git * [new branch] master -> master /git-study .git├─ compress.js└─ │ 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가
  79. 79. • README.md 파일 추가 후 원격저장소로 push • commit message : “README 추가” 1 Compress.js 2 —- 3 4 같은 문자가 연속적으로 반복되는 경우에 그 반복 횟수를 표시하여 문자열 압축하기
  80. 80. /git-study .git├─ compress.js└─ │ README.md└─ $> git add READMD.md $> git commit -m “READMD 추가” [master 650b6d7] READMD.md 추가 1 file changed, 4 insertions(+) create mode 100644 README.md $> git push origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 416 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@github.com:insanehong/git-study.git b6f9dc3..650b6d7 master -> master 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가 650b6d7 READMD 추가
  81. 81. Tips
  82. 82. • refs : object의 SHA-1 값을 저장한 파일들, ./git/refs 하위 모든 파일 • branch : 어떤 작업들 중 마지막 작업을 가리키는 레퍼런스 • branch name : branch 의 last commit 에 대한 alias (master) • HEAD : 현재 checkout 되어 있는 커밋을 가리키는 레퍼런스 • tag : 특정 commit 을 가리키는 object
  83. 83. 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가 master branch master HEAD650b6d7 READMD 추가
  84. 84. git reset “This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. If <mode> is omitted, defaults to "--mixed". The <mode> must be one of the following:” - https://www.kernel.org/pub/software/scm/git/docs/git-reset.html -
  85. 85. • Working tree 를 유지하며 되돌리기 
 $> git reset <commit>, --mixed • Working tree, index 를 유지하며 되돌리기 
 $> git reset --soft <commit> • 모두 되돌리기 $> git reset --hard <commit>
  86. 86. $> git reset b6f9dc3 $> git status -s ?? README.md 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가 master HEAD 650b6d7 READMD
  87. 87. $> git reset --soft f5cd615 $> git status -s M compress.js ?? README.md 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 master HEAD 650b6d7 READMD
  88. 88. $> git reset --hard 650b6d7 HEAD is now at 650b6d7 READMD 추가 $> git status On branch master nothing to commit, working directory clean 5525f5f 문제풀이 완료 f5cd615 버그 수정 b6f9dc3 헤더 추가 master HEAD650b6d7 READMD 추가
  89. 89. git clone “Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.” - https://www.kernel.org/pub/software/scm/git/docs/git-clone.html -
  90. 90. “다른 프로젝트에 참여하거나(Contribute) Git 저장소를 복사하고 싶을 때 사용.”
  91. 91. • remote 받아오기 
 $> git clone <url> • 디렉토리를 생성하면서 remote 받아오기 
 $> git clone <url> <directory> • remote 의 특정 branch 를 지정
 $> git clone <url> -b <branch>
  92. 92. /git-study .git├─ compress.js└─ │ README.md└─ Github https://github.com/insanehong/git-study.git
  93. 93. /workspace/ $> git clone git@github.com:insanehong/git-study.git git-study-2 Cloning into 'git-study-2'... remote: Counting objects: 12, done. remote: Compressing objects: 100% (7/7), done. remote: Total 12 (delta 2), reused 12 (delta 2) Receiving objects: 100% (12/12), done. Resolving deltas: 100% (2/2), done. Checking connectivity... done. $> cd git-study-2 git-study└─
  94. 94. /git-study-2 .git├─ compress.js└─ │ README.md└─ /workspace/ git-study └─ ├─
  95. 95. • git stash • git blame • git checkout • git bisect • git ls-files • git fetch • git merge • git rebase • git pull • git rm • git mv
  96. 96. http://www.flickr.com/photos/adulau/8442476626/
  97. 97. insanehong.talk.end(“Thanks. Bye!!”)
  98. 98. Git is a just tool! • http://git-scm.com/book/ko/v1 • https://www.kernel.org/pub/software/scm/git/ • Thanks toYi Eung Jun at NAVER LABS (http://npcode.com) • 본자료에 사용된 commit internal 부분은Yi Eung Jun 님의 git basic 강의 자료를 참고 했습니다. Reference
  99. 99. Git is a just tool! 본 자료는 14.12.20 KGUG(Korea Git User Group) 주최 대학생 대상 Git 교육인 “Getting Started with git” 에서 발표된 “Git Basic Commands” 의 발표내용을 담고 있습니다. 본 자료는 크리에이티브 커먼즈 저작자표시-비영리-변경금지(CC BY-NC-ND) 3.0 Unported 라이선스 에 따라 이용할 수 있습니다. 본 자료에 사용 된 이미지들은 Creative Common License 를 따르며 이미지 출처는 해당 이미지 하단에 기제 되어 있습니다. twitter : @insanehong email : insanehong@gmail.com

×