블로그 이미지
윤영식
Full Stacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2013. 1. 13. 21:14 Git, GitHub

원격저장소로 GitHub을 이용하고 있고, Branch를 만들고 삭제하는 방법에 대해서 알아보자. 


1) 브랜치 생성, 삭제 순서 

  - local 저장소에 branch를 만든다 

  - remote 저장소로 branch를 push 하여 추적(tracking) 한다 

  - 사용하지 않는 branch는 삭제한다 

////////////////////////////////////////////////

// 새로운 브랜치를 생성하고 checkout 한다 

$ git checkout -b shopping_cart

Switched to a new branch 'shopping_cart'


////////////////////////////////////////////////

// 원격 저장소로 브랜치를 push 한다 

$ git push origin shopping_cart

Username for 'https://github.com':

Password for 'https://ysyun@yuwin.co.kr@github.com':

Total 0 (delta 0), reused 0 (delta 0)

To https://github.com/ysyun/pro_git.git

 * [new branch]      shopping_cart -> shopping_cart


// github에 새로운 브랜치가 추가 되었다. 


///////////////////////////////////////////////

// 새로운 파일을 추가하고 원격으로 push 한다 

$ touch cart.js

$ git add cart.js

$ git commit -m "add cart javascript file"

[shopping_cart 4856f8d] add cart javascript file

 0 files changed

 create mode 100644 cart.js


$ git push

Username for 'https://github.com':

Password for 'https://ysyun@yuwin.co.kr@github.com':

Counting objects: 3, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 245 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

To https://github.com/ysyun/pro_git.git

   f42a865..4856f8d  shopping_cart -> shopping_cart


///////////////////////////////////////////////

// 로컬 브랜치 내역 과 원격 브랜치 내역을 본다 

$ git branch

  master

* shopping_cart


$ git branch -r

  origin/HEAD -> origin/master

  origin/master

  origin/shopping_cart


////////////////////////////////////////////////////

// 로컬의 새로 추가한 shopping_cart 브랜치를 삭제한다

$ git checkout master

Switched to branch 'master'


$ git branch -d shopping_cart

error: The branch 'shopping_cart' is not fully merged.

If you are sure you want to delete it, run 'git branch -D shopping_cart'.


$ git branch -D shopping_cart

Deleted branch shopping_cart (was 4856f8d).


$ git branch

* master


///////////////////////////////////////////////

// 로컬에 이제 shopping_cart 브랜치가 없다 다시 복구 하고 싶다면

// 원격 저장소를 통하여 checkout 하면 된다 

$ git checkout shopping_cart

Branch shopping_cart set up to track remote branch shopping_cart from origin.

Switched to a new branch 'shopping_cart'


$ git branch

  master

* shopping_cart


///////////////////////////////////////////////

// 원격의 브랜치 내역을 보자

// 어떤 브랜치들이 존재하는지 한눈에 알 수 있다 

$ git remote show origin

* remote origin

  Fetch URL: https://github.com/ysyun/pro_git.git

  Push  URL: https://github.com/ysyun/pro_git.git

  HEAD branch: master

  Remote branches:

    master        tracked

    shopping_cart tracked

  Local branches configured for 'git pull':

    master        merges with remote master

    shopping_cart merges with remote shopping_cart

  Local refs configured for 'git push':

    master        pushes to master        (up to date)

    shopping_cart pushes to shopping_cart (up to date)


///////////////////////////////////////////////

// 원격에 있는 브랜치를 삭제 하자 

$ git push origin :shopping_cart

Username for 'https://github.com':

Password for 'https://ysyun@yuwin.co.kr@github.com':

To https://github.com/ysyun/pro_git.git

 - [deleted]         shopping_cart


// shopping_cart 브랜치가 삭제되었음을 알 수 있다

$ git remote show origin

* remote origin

  Fetch URL: https://github.com/ysyun/pro_git.git

  Push  URL: https://github.com/ysyun/pro_git.git

  HEAD branch: master

  Remote branch:

    master tracked

  Local branch configured for 'git pull':

    master merges with remote master

  Local ref configured for 'git push':

    master pushes to master (up to date)


///////////////////////////////////////////////

// remote 브랜치 clean up 하기 

$ git remote prune origin


UserXP@NUKNALEA /d/Git_repositories/pro_git (master)

$ git remote show origin

* remote origin

  Fetch URL: https://github.com/ysyun/pro_git.git

  Push  URL: https://github.com/ysyun/pro_git.git

  HEAD branch: master

  Remote branch:

    master tracked

  Local branch configured for 'git pull':

    master merges with remote master

  Local ref configured for 'git push':

    master pushes to master (up to date)


2) master가 아닌 local 브랜치를 remote 저장소의 master 브랜치에 push 하기 

  - 조건 : local 저장소의 브랜치가 master가 아닌 다른 브랜치로 checkout 되어 있을 경우 예) shopping_cart

  - 명령 :  git push [원격저장소 주소 alias] [로컬저장소명칭]:master

  - 예 : git push origin shopping_cart:master

  - 의미 : origin 원격 주소의 master 브랜치에 local저장소의 shopping_cart 브랜치를 push 한다


posted by 윤영식
2013. 1. 13. 20:40 Git, GitHub

Git clone후에 두명 이상이 작업을 한다. 그리고 같은 파일을 수정하여 Remote 저장소에 Push 할 경우 merge conflict가 발생한다. 이를 해결하기 위한 과정을 알아보자 


1) merge conflict 조건

  - 한명이 같은 파일을(예, README.md) 수정하고 GitHub(remote repository)에 push하였다. 

  - 다른 사람이 README.md 파일 내역을 수정하고 GitHub에 push 하려고 한다. 

  - 이때 git은 fail 메시지를 뱃으면서 push 되지 않는다. 

   

  - github에 한명이 push하여 분홍색으로 있고, gregg는 local 저장소에 commit된 내역을 push 하려고 할 경우


2) merge conflict 해결하기 

  - push : GitHub에 push하려 했더니 conflict가 발생함 

  - pull : GitHub 변경내용을 local 저장소와 merge 하기 

  - edit : 충돌나는 부분이 있다면 직접 편집하기 

  - commit -a : 다시 모든 파일을 commit 하기 

  - push : 변경된 내역을 다시 GitHub에 push하기 

/////////////////////////////////////////////////////////////////////

// 이미 github에는 README.md 파일이 수정되어 있음 (위 그림의 분홍색)

// "It was changed in Github directly by yun dowon" 메시지 commit

///////////////////////////////////////////////////////////////////////////////////////

// README.md  파일에 

// "checkout merge conflict with same file when another change it differently." 내용을 추가함

// (위 그림의 초록색 gregg로 보면 됨)

$ cat README.md

pro_git

=======


test pro git books

checkout merge conflict with same file when another change it differently.


// 추가된 내용을 commit 함 

$ git commit -am "change README.md"

[master fbf9382] change README.md

 1 file changed, 2 insertions(+), 1 deletion(-)


/////////////////////////////////////

// GitHub에 반영할려고 함 

$ git push

Username for 'https://github.com':

Password for 'https://ysyun@yuwin.co.kr@github.com':

To https://github.com/ysyun/pro_git.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://github.com/ysyun/pro_git.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')

hint: before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.


////////////////////////////////////////////////

// pull 을 수행 

$ git pull

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From https://github.com/ysyun/pro_git

   9ae6fb2..c917ae5  master     -> origin/master

Auto-merging README.md

CONFLICT (content): Merge conflict in README.md

Automatic merge failed; fix conflicts and then commit the result.


// 현재 상태를 확인

$ git status

# On branch master

# Your branch and 'origin/master' have diverged,

# and have 1 and 1 different commit each, respectively.

#

# Unmerged paths:

#   (use "git add/rm <file>..." as appropriate to mark resolution)

#

#       both modified:      README.md

#

no changes added to commit (use "git add" and/or "git commit -a")


////////////////////////////////////////////////////////////////

// README.md 파일이 GitHub내용과 Local 저장소 내용이 합쳐졌다

$ cat README.md

pro_git

=======


test pro git books

<<<<<<< HEAD

checkout merge conflict with same file when another change it differently.  <-- Local 저장소 내역

=======

It was changed in GitHub directly by yun dowon  <-- Remote 저장소 내역

>>>>>>> c917ae5f7787844b63826a460d82a998bad08a7f 


///////////////////////////////////////////

// 변집기를 통하여 직접 내용을 적절히 수정함

$ vi README.md

$ git status

# On branch master

# Your branch and 'origin/master' have diverged,

# and have 1 and 1 different commit each, respectively.

#

# Unmerged paths:

#   (use "git add/rm <file>..." as appropriate to mark resolution)

#

#       both modified:      README.md

#

no changes added to commit (use "git add" and/or "git commit -a")


///////////////////////

// 다시 commit을 한다 

$ git commit -a

[master f42a865] Merge branch 'master' of https://github.com/ysyun/pro_git


UserXP@NUKNALEA /d/Git_repositories/pro_git (master)

$ git status

# On branch master

# Your branch is ahead of 'origin/master' by 2 commits.

#

nothing to commit (working directory clean)


/////////////////////////////////////////////////

// conflict가 해결되었으면 다시 push 하여 통합한다

$ git push

Username for 'https://github.com':

Password for 'https://ysyun@yuwin.co.kr@github.com':

Counting objects: 10, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (6/6), done.

Writing objects: 100% (6/6), 734 bytes, done.

Total 6 (delta 3), reused 0 (delta 0)

To https://github.com/ysyun/pro_git.git

   c917ae5..f42a865  master -> master


////////////////////////

GitHub에 push된 내용 


3) merge conflict 시에 pull 의미 

  - git fetch : remote 브랜치 하나가 local 저장소로 내려온 것이고, local 저장소에 commit 된 상태는 아님 

  - git merge origin/master : local 저장소의 master와 origin/master 브랜치를 merge 함 

  - pull = git fetch + git merge origin/master 두개가 동시에 수행된 것임 

posted by 윤영식
2013. 1. 13. 20:00 Git, GitHub

git에서 merge를 할 경우 내용으로 fast-forward merge라는 용어가 나온다. 이에 대해서 알아보자.


1) fast-forwad merge 의 조건

  - master에서 새로운 branch를 만든다 

  - 새로운 branch에서 추가한 파일을 commit한다. 이때 master에서는 아무런 commit 내용도 없다.

   

//////////////////////////////////////////////////////

// cat branch를 만들고 cat으로 checkout 한다 (-b 옵션)

$ git branch -b cat


$ git branch

* cat

 master


///////////////////////////////////////////////////////////////

// 파일을 하나 만들고 commit 한다. 새로운 commit 이 생긴 것이다. 

$ echo "dowon" > cat.txt

$ git add cat.txt

$ git commit -m "add cat.txt"

[cat 1e6ea90] add cat.txt

The file will have its original line endings in your working directory.

 1 file changed, 1 insertion(+)

 create mode 100644 cat.txt


// cat branch안에 cat.txt 파일이 보인다

$ ls

README.md  build.gradle  cat.txt  todo.txt


// master branch로 이동을 한다 

$ git checkout master

Switched to branch 'master'

Your branch and 'origin/master' have diverged,

and have 1 and 3 different commits each, respectively.


////////////////////////////////////////////

// master에는 cat.txt 파일이 존재하지 않는다. 

$ ls

README.md  build.gradle  todo.txt


////////////////////

// merge를 수행한다

$ git merge cat

Updating 8ee3f5e..1e6ea90

Fast-forward

 cat.txt | 1 +

 1 file changed, 1 insertion(+)

 create mode 100644 cat.txt


////////////////////////////////////////////////
// 사용하지 않는 cat branch는 삭제한다. (-d 옵션)
$ git branch -d cat 


posted by 윤영식
2013. 1. 13. 19:32 Git, GitHub

로컬에서 Git을 사용하다가 실수로 Commit을 할 경우 다시 이전 상태로 원복하고 싶을 때 가장 많이 사용하는 명령를 알아보자.


1) 방금 commit한 내용을 staging area로 돌려 놓고 싶을 경우 

  - 명령 : git reset --soft HEAD^

  - HEAD : 현재 commit의 포인터,  ^ : 이전 것,  --soft : staging으로 옮기기

$ git reset --soft HEAD^


// commit 했던 LICENSE 파일이 staged area에 존해함

$ git status

# On branch master

# Changes to be committed:

#   (use "git reset HEAD <file>..." to unstage)

#

#       new file:   LICENSE

#


2) 방금 commit 한 것에 다른 파일로 추가 하여 넣고 싶을 경우 (commit은 증가하지 않음)

  - 명령 : git commit --amend -m "add new file"

  - --amend : 최근 기존 commit에 추가하기 

// 새로운 파일을 만든다 

$ touch todo.txt

$ touch add todo.txt 


// 기존 commit에 todo.txt 파일 추가하기 

$ git commit --amend -m "new thing file"

[master 18b3bb7] new thing file

  1 file changed, 3 insertions(+)

 create mode 100644 todo.txt

 create mode 100644 LICENSE


3) 현재 commit한 것을 없애버리고 싶을 경우 (방금 commit한 내용이 staging 가지 않고 없어진다)

  - 명령 : git reset --hard HEAD^

//현재 commit 내역을 본다 

$ git log

commit 18b3bb76c5d16c76221d45b1bc61b483001191d4

Author: Yun DoWon <ysyun@yuwin.co.kr>

Date:   Sun Jan 13 18:43:03 2013 +0900


    new thing file


commit 329db048ff7af2d417588e28da50a6c53fb1bd84

Author: Yun DoWon <ysyun@yuwin.co.kr>

Date:   Thu Dec 27 11:07:26 2012 +0900


    add content in build.gradle


// 최신 commit 18b3bb76c5d16c76221d45b1bc61b483001191d4 을 삭제했다

$ git reset --hard HEAD^

HEAD is now at 329db04 add content in build.gradle


UserXP@NUKNALEA /d/Git_repositories/pro_git (master)

$ git log

commit 329db048ff7af2d417588e28da50a6c53fb1bd84

Author: Yun DoWon <ysyun@yuwin.co.kr>

Date:   Thu Dec 27 11:07:26 2012 +0900


    add content in build.gradle


4) 그럼 현재 commit 에서 두단계 이전 commit으로 이동하면서 앞 두단계를 삭제하고 싶다면 

  - 명령 : git reset --hard HEAD^^

  - ^ 이전, ^^ 이전에 이전 (두단계 이전)

posted by 윤영식
2013. 1. 13. 12:42 NodeJS/Modules

Socket.io안에서 사용되는 WebSocket 에 대한 프로토콜의 위치에 대하여 알아보자.


1) WebSocket 등장배경

  - 처음엔 iframe을 활용

  - 그다음은 XMLHTTPRequest를 이용

  - HTML5에 와서 Websocket 등장

  - SPDY 포로토콜을 통한 전송 압축 (성능향상)

  - Server Send Events (SSE)에 대한 이해


2) SPDY 프로토콜 등장배경

  - 실시간 Push 효과적 (압축 및 암호)

  - Node-SPDY 

  - Chrome/Firefox 지원


  - chrome://net-internals/#spdy  명령을 통해서 Chrome의 다양한 통신 내역을 살펴볼 수 있다.


3) 결론
  - Chrome이나 Firefox에서만 구동 될 수 있는 솔루션을 만들경우
  - Real-time Push 서비스를 할 경우 성능을 높이기 위해 사용
  - Node.js를 사용할 경우도 지원 


posted by 윤영식