본 자료는 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 를 따르며 이미지 출처는 해당 이미지 하단에 기제 되어 있습니다.
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) -
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 -
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 -
41. • 자세한 내용을 확인 할때
$> git status
• 파일들의 변경 상태만 확인 할때
$> git status -s
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. /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
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. /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. 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. 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. 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
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. 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. • working directory 와 index 를 비교
$> git diff
• 커밋 간 차이점 을 비교
$> git diff <commitA>..<commitB>
• index 와 HEAD를 비교
$> git diff --staged
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. • 원격 저장소 추가
$> git remote add <alias> <url>
• 원격 저장소 alias 변경
$> git remote rename <old> <new>
• 원격 저장소 url 변경
$> git remote set-url <alias> <url>
• 원격 저장소 확인
$> git remote -v
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. $> 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.
80. • README.md 파일 추가 후 원격저장소로 push
• commit message : “README 추가”
1 Compress.js
2 —-
3
4 같은 문자가 연속적으로 반복되는 경우에 그 반복 횟수를 표시하여 문자열 압축하기
81. /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 추가
83. • refs : object의 SHA-1 값을 저장한 파일들, ./git/refs 하위 모든 파일
• branch : 어떤 작업들 중 마지막 작업을 가리키는 레퍼런스
• branch name : branch 의 last commit 에 대한 alias (master)
• HEAD : 현재 checkout 되어 있는 커밋을 가리키는 레퍼런스
• tag : 특정 commit 을 가리키는 object
85. 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 -
86. • Working tree 를 유지하며 되돌리기
$> git reset <commit>, --mixed
• Working tree, index 를 유지하며 되돌리기
$> git reset --soft <commit>
• 모두 되돌리기
$> git reset --hard <commit>
87. $> git reset b6f9dc3
$> git status -s
?? README.md
5525f5f 문제풀이 완료
f5cd615 버그 수정
b6f9dc3 헤더 추가 master HEAD
650b6d7 READMD
88. $> git reset --soft f5cd615
$> git status -s
M compress.js
?? README.md
5525f5f 문제풀이 완료
f5cd615 버그 수정
b6f9dc3
master HEAD
650b6d7 READMD
89. $> 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 추가
90. 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 -
99. 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
100. 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