Passion/Programming

git 사용법

sunshout 2013. 4. 9. 10:05

 

¡ 개인별 식별 정보 입력

사용자 이름과 이메일 정보를입력함

 

git config --global user.name “Choonho Son”

git config --global user.email choonho.son@gmail.com

 

¡ 에디터 변경 (기본은 vim 으로 되어 있슴)

git config --global core.editor emacs

 

설정 정보는 ~/.gitconfig 파일에 적힘

[user]

        name = Choonho Son

        email = choonho.son@gmail.com

[core]

        editor = vim

 

¡ git 패치를 보내기 위한 sendmail 설정

 

git config --global sendemail.smtpserver smtp.gmail.com

git config --global sendemail.smtpserverport 587

git config --global sendemail.smtpencryption tls

git config --global sendemail.smtpuser choonho.son@gmail.com


 

¡ 소스 clone

명령어 : git clone <git URL> <local directory name>

(Xen)

git clone git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git


(netdev)

git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git netdev

 

(linux-stable)


¡ Branch 관련 명령어

git branch <new branch>

branch는 단순히 master에서 새로운 브랜치를 만든다는 의미.

현재 branch 확인하기

git branch

 

[root@openxen xen]# git branch ovs

[root@openxen xen]# git branch

* master

Ovs

[root@openxen xen]# git checkout ovs

Switched to branch 'ovs'

[root@openxen xen]# git branch

  master

* ovs

 

새로 만든 branch를 사용하기 위해서는 checkout를 해야 한다.


¡ Branch Format patch

새로운 브랜치에서 만든 commit 들을 patch 파일 형태로 만들어 준다
master branch 대비 2개의 commit 이 존재하고, 새로 만든 두개의 commit을 patch 파일로 만들어 줌

sunshout@choonho:~/opensource/qemu-rebase$ git format-patch master
0001-Add-block_rebase-API.patch
0002-Add-bdrv_rebase_backing_file.patch

현재 commit 에서 2개를 patch 파일로 만들고 싶을 때

git format-patch -2


git stash <--> git pop

- HEAD 이후 고치고 있던 내용을 임시로 저장하고, 이전상태로 복원하는 기능


references:

https://github.com/autotest/autotest/wiki/GitWorkflow


최초 google project host에 initial commit을 넣을때

git remote add origin https://Choonho.Son@code.google.com/p/quicksee/

git push origin master


local의 repo 를 remote 로 복사하는 방법

git push --mirror https://github.com/ghuser/repo.git


¡ Git remote add


¡ Git rebase 하기

git remote add upstream git://git.qemu.org/qemu.git
=> 외부 git 을 가져옴

git fetch upstream
=> 가져온 git 의 내용까지 download함

rebase upstream to master

git pull --rebase upstream master

git checkout -b 2.1.0 v2.1.0
=> branch 2.1.0 을 만드는데 tag v2.1.0 commit 까지 

git checkout <내거>
git checkout -b <new 내거>, 혹시 몰라서 새로운 branch를 만든고 한거(Optional)
git rebase 2.1.0

git checkout -b <new> -t upstream/master

git mergetool 을 하면 내가 고쳐야 하는 내용이 나옴 (conflict 날 때)
==> 실패하면 다시 git rebase --abort


git rebase --continue

Merge

  • Let's say you have created a branch for the purpose of developing a single feature. When you want to bring those changes back to master, you probably want merge (you don't care about maintaining all of the interim commits).

Rebase

  • A second scenario would be if you started doing some development and then another developer made an unrelated change. You probably want to pull and then rebase to base your changes from the current version from the repo.

¡ git push

자신의 local branch 를 remote의 새로운 local branch로 올리기

git push <remote-name> <local-branch-name>:<remote-branch-name
git push origin 2.1.0:stable-2.1.0

¡ Tag 정보 보기 (git show-ref --tags)

 root@cnode03-m:~/dpdk# git show-ref --tags

84551840802efa37eb9fec9c90037d1a8c3f61ee refs/tags/v1.2.3r0

a36416a756094a0a7b9ca5fdd1a6245b8863a4ec refs/tags/v1.2.3r1

35eeed870964adf6f6e35ee694ffe8a3278d2665 refs/tags/v1.2.3r2

34e42c51cd3f41065aeb6a842056147d9e6a3979 refs/tags/v1.2.3r3

d92f1a8e0b11e5941acafecafc69f7a2c1246422 refs/tags/v1.2.3r4

51f7b9e0466d000a9d9e30d6dc8a9a3a03519c40 refs/tags/v1.3.0r0

a4e26550f8104e8493e0bef4b27a6cf053f352ac refs/tags/v1.3.1r0

f81ba944c287958032be7e1426eaae38d0912de5 refs/tags/v1.3.1r1

28e79381e8c4a318f6587582f78912dfa25c44dc refs/tags/v1.3.1r2

d0defda5efcff12696b6e939e3112201282ce52e refs/tags/v1.3.1r3

2d94b2ac34dcb8c5e90b4722dd0770c46abe02cd refs/tags/v1.4.0r0

29f0f724fd2264c6d03b79b9255d0190fa410428 refs/tags/v1.4.1r0

002687465115d75818a13432af109a48e63598c7 refs/tags/v1.4.1r1

358ba686b76339c6c783ebc014661e2ee7f585f7 refs/tags/v1.4.1r2

8e1f2cf79cbf611177da8f46924989b21fe5ca0c refs/tags/v1.5.0r0

f6b4789329f18e02c92390c841f958883e4d349e refs/tags/v1.5.0r1

74a5ef19aa55c69390b5ede5521770fb015fb3d9 refs/tags/v1.5.0r2

29229e7a2ff60e45394780f2ae00b038d1e1f14f refs/tags/v1.5.1r0

3a2fe0c727ec107631aeece76b089c2037263fc7 refs/tags/v1.5.1r1

637e3d53d2f74e84a24f44f7652bc4a93b7e5a80 refs/tags/v1.5.1r2

3f6ad04283ef7575934af0a729c4108e91157b0c refs/tags/v1.5.2r0

cdbe508682b6129575649a031c5f43f5965a2bf4 refs/tags/v1.5.2r1

6ae3ef09dc66d96849a72cf230673d3cd7099e3d refs/tags/v1.5.2r2

91beff071abb4d80862bf9237a38141fe4c6827a refs/tags/v1.6.0r0

6fc667cd742072edaa7bcb8c19759d86eb099306 refs/tags/v1.6.0r1

ceac75ee292483ae715a7db752117bff722dfe8a refs/tags/v1.6.0r2

73e315113e1045614e31bb04d1308e33eaf01dc2 refs/tags/v1.7.0

b768cdcebe818252f2039c5a99bcdaff66c5c91c refs/tags/v1.7.0-rc1

6c142dcf73333a149b7f0a1a0ebaedffc7a0254e refs/tags/v1.7.0-rc2

1cd5a1f14e14abc663f330aed1d919a8501675c4 refs/tags/v1.7.0-rc3

bb131c1e1e89acfed4018e77a8d67aeb8ce41e95 refs/tags/v1.7.0-rc4

9a9149ac3b2ac82ec10fb687c77602992226ec05 refs/tags/v1.7.1

¡ 생성한 tag 를 remote 에 push 하기

git push --tags

¡ tag 로 revert 하기

git reset --hard "해당 tag_name"

¡ 특정 파일과 관련된 commit history 를 찾기

git log -- [filename]
git log --pretty=oneline

¡git reset 과 원복


git reset <commit #>

reset history 보기 (git reflog)

root@choonho-dev:/storage/vpp# git reflog
8527f12 HEAD@{0}: reset: moving to 8527f12b525181b47cc7c0c9e943a743b1a3b19e
de5fec9 HEAD@{1}: reset: moving to de5fec943ab12933696db5b0abf287dea335e312
2d8bf30 HEAD@{2}: reset: moving to 2d8bf304230102a6d9b312b98315418617798175

원복 하기 (git reset HEAD@{#})

root@choonho-dev:/storage/vpp# git reset HEAD@{3}


git submodule
git submodule은 submodule이 add된 상태의 commit 까지만 받음
이후 commit까지 받아 오고 싶을 때는
git submodule foreach git pull origin master
# 비밀번호를 저장하고 싶을  때
git config --global credential.helper cache