달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
Android 에서는 Git 를 내부적으로 사용하면서 Repo 를 Wrapper 로 이용한다.
.repo 안에 어떻게 되어 있는 건지 궁금해서 들여다 봤다.
앞으로 더 봐야겠지만 오늘 분석한 것을 정리한다.

<download>
Android Source 전체를 받을 필요는 없고, repo sync 까지만 해서 .repo 안에 구조를 본다.

mkdir mydroid
cd mydroid/
repo init -u git://android.git.kernel.org/platform/manifest.git

<.repo>
.repo 안에 repo command 를 구현한 repo directory 가 있고,
.repo 내 프로젝트 설정 정보를 담고 있는 manifest.xml 파일이 있다.
그런데 manifest.xml 는 symbolic link 이고 실제 파일은 manifest directory 에 있는 default.xml 이다.

$ tree -L 1 .repo
.repo
|-- manifests
|-- manifests.git
|-- manifest.xml -> manifests/default.xml
`-- repo

그런데 manifest.git 는 어떤 directory 인지 궁금했는데,
manifest.xml 을 git 로 관리하는 것이다.

참고적으로 repo sync 를 통해 Source 를 받고 나니,
project 에 대한 정보가 있는 파일이 더 생겼다.
이 부분은 나중에 확인해 봐야겠다.

// would be like this after repo sync
$ tree -L 1 .repo/
.repo/
|-- manifests
|-- manifests.git
|-- manifest.xml -> manifests/default.xml
|-- project.list
|-- projects
`-- repo

<manifests VS manifests.git>
directory가 두 개가 있는데 왜 두 개인지 궁금했다.

안을 들여다 보기 전에 우선 용량부터 확인했더니,
둘 다 용량이 작은데, manifests 가 훨씬 작았다.

$ du -sh .repo/manifests
104K    .repo/manifests
$ du -sh .repo/manifests.git/
1.4M    .repo/manifests.git/

ls 로 파일을 보니, manifests 에는 파일이 몇 개 있고,
.git 가 있는 것을 보니 Git 로 관리하고 있는 것으로 보인다.

$ ls -l .repo/manifests
total 100
drwxr-xr-x 3 jaewon jaewon  4096 2011-07-29 20:48 .
drwxr-xr-x 6 jaewon jaewon  4096 2011-08-13 22:46 ..
-rw-r--r-- 1 jaewon jaewon 21776 2011-07-29 20:46 3.0-base.xml
-rw-r--r-- 1 jaewon jaewon 22340 2011-07-29 20:46 3.1-base.xml
-rw-r--r-- 1 jaewon jaewon 23240 2011-07-29 20:46 3.2-base.xml
-rw-r--r-- 1 jaewon jaewon 14378 2011-07-29 20:46 default.xml
drwxr-xr-x 2 jaewon jaewon  4096 2011-08-13 22:21 .git

그런데 .git 안을 보니 주요 파일들이 Symbolic Link 일 뿐 실제 파일이 아니고,
manifest.git 에 있는 것이 실제 파일이다.
심지어 packed-refs 와 svn 는 target 이 없는 broken link 이다.

$ ls -l .repo/manifests/.git/
total 8
lrwxrwxrwx 1 jaewon jaewon  26 2011-08-13 23:10 config -> ../../manifests.git/config
lrwxrwxrwx 1 jaewon jaewon  31 2011-08-13 23:10 description -> ../../manifests.git/description
-rw-r--r-- 1 jaewon jaewon  24 2011-08-13 23:10 HEAD
lrwxrwxrwx 1 jaewon jaewon  25 2011-08-13 23:10 hooks -> ../../manifests.git/hooks
-rw-r--r-- 1 jaewon jaewon 385 2011-08-13 23:10 index
lrwxrwxrwx 1 jaewon jaewon  24 2011-08-13 23:10 info -> ../../manifests.git/info
lrwxrwxrwx 1 jaewon jaewon  24 2011-08-13 23:10 logs -> ../../manifests.git/logs
lrwxrwxrwx 1 jaewon jaewon  27 2011-08-13 23:10 objects -> ../../manifests.git/objects
lrwxrwxrwx 1 jaewon jaewon  31 2011-08-13 23:10 packed-refs -> ../../manifests.git/packed-refs
lrwxrwxrwx 1 jaewon jaewon  24 2011-08-13 23:10 refs -> ../../manifests.git/refs
lrwxrwxrwx 1 jaewon jaewon  28 2011-08-13 23:10 rr-cache -> ../../manifests.git/rr-cache
lrwxrwxrwx 1 jaewon jaewon  23 2011-08-13 23:10 svn -> ../../manifests.git/svn

당연하겠지만 그래서 .git 가 차지하는 용량도 무척 작다.

$ du -sh .repo/manifests/.git/
12K    .repo/manifests/.git/

Symbolic Link 라서 이건 껍데기려니 하고,
그냥 diff 로 차이가 있는 파일을 봤다.
다른 건 그럭저럭 눈에 안 뜨이는데 HEAD 파일이 다르다는 것이 이상하다.

$ diff -qr .repo/manifests/.git .repo/manifests.git
Only in .repo/manifests.git: branches
Only in .repo/manifests.git: FETCH_HEAD
Files .repo/manifests/.git/HEAD and .repo/manifests.git/HEAD differ
Only in .repo/manifests/.git: index
Only in .repo/manifests/.git: packed-refs
Only in .repo/manifests.git: .repopickle_config
Only in .repo/manifests/.git: svn

<manifest>
manifest directory 를 좀 더 들여다 봤다.

$ cd .repo/manifests

config 파일을 열어 환경 설정을 보니,
origin remote 와 default branch 를 가진 일반적인 형태다.
다른 파일들이 Symbolic Link 이지만 config 파일은 mainifest.git 의 config 와 같은 내용이었다.

.repo/manifests$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = true
[remote "origin"]
    url = git://android.git.kernel.org/platform/manifest.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "default"]
    remote = origin
    merge = refs/heads/master

본 김에 HEAD commit 을 봤다.
Log Message 를 보니 새 project 를 만들었나 보다.

.repo/manifests$ git log --oneline HEAD^!
dc01e28 Add new projects

예상대로 HEAD 는 정상적으로 heads/default 즉 local default branch 를 의미했다.

.repo/manifests$ cat .git/HEAD
ref: refs/heads/default

remote branch 를 포함해서 전체 branch 를 보니,
default 는 origin/master 즉 origin remote 에서 master branch 를 upstream 으로 하고 있다.
그밖에 Android 각 version 별로 branch 를 따로 만들어서 사용했던 것 같다.
내부적으로 최신 version 으로 merge 했을 것 같지만.

.repo/manifests$ git branch -avv
* default                                  dc01e28 [origin/master] Add new projects
  remotes/origin/android-1.5               1b4d95f fixed duplicate entry
  remotes/origin/android-1.5r2             2de7a11 Manifest for 1.5r2
  (생략)
  remotes/origin/master                    dc01e28 Add new projects
  (생략)

<manifest.git>
그럼 manifest.git directory 는 어떻게 되어 있을까?

$ cd .repo/manifests.git/

branch 정보를 봤는데, manifest 와 같은 것 같다.
아라? 그런데 local default branch 에 현재 branch 를 가리키는 * 가 없다.
HEAD 값이 어떻게 되어 있길래?

.repo/manifests.git$ git branch -avv
  default                                  dc01e28 [origin/master] Add new projects
  remotes/origin/android-1.5               1b4d95f fixed duplicate entry
  remotes/origin/android-1.5r2             2de7a11 Manifest for 1.5r2
  ...
  remotes/origin/master                    dc01e28 Add new projects
  ...

우선 config 를 봤다.
특별한 사항은 없다.

.repo/manifests.git$ cat config
[core]
    repositoryformatversion = 0
    filemode = true
[remote "origin"]
    url = git://android.git.kernel.org/platform/manifest.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "default"]
    remote = origin
    merge = refs/heads/master

그럼 HEAD 는 어떻게 되어 있을까?
default branch 가 아니라 master branch 로 되어 있다!!!
왜 이렇게 해 놨을까??

.repo/manifests.git$ cat HEAD
ref: refs/heads/master

heads 즉 local branch 중에 master 는 없는데 말이다.

.repo/manifests.git$ ls refs/heads/
default

이렇게 HEAD가 잘못 되어 있으니까,
git log 와 같은 것도 안 되는 것이 당연하다.

.repo/manifests.git$ git log
fatal: bad default revision 'HEAD'

테스트용으로 master ref 를 만들어본다면,
git log 가 잘 된다.
manifest.git 내에서 git command 를 하지 못 하도록 일부러 막았을지도 모르겠다.

.repo/manifests.git$ cp refs/heads/default refs/heads/master
.repo/manifests.git$ git log --oneline HEAD^!
dc01e28 Add new projects
.repo/manifests.git$ git branch -vv
  default dc01e28 [origin/master] Add new projects
* master  dc01e28 Add new projects
.repo/manifests.git$ rm refs/heads/master


Posted by neodelicious
|
<LWN>
http://lwn.net/Articles/driver-porting/

<Kernel Doc>
Documentation/filesystems/sysfs.txt
Documentation/firmware_class/
Documentation/driver-model/
Documentation/kobject.txt

<header file>
#include <linux/device.h>
#include <linux/kojbect.h>
#include <linux/sysfs.h>


Posted by neodelicious
|

cscope

Tool/editor & source viewer 2011. 5. 23. 23:22
cscope - interactively examine a C program

i.e) cscope -R
i.e) cscope -b -q -k -R
i.e) cscope -d

-sdir  Look in dir for additional source files. This option is ignored if source files are given on the command line.

-R     Recurse subdirectories during search for source files.

-b     Build the cross-reference only.

-q     Enable fast symbol lookup via an inverted index. This option causes cscope to  create  2  more  files (default  names  ``cscope.in.out''  and  ``cscope.po.out'')  in addition to the normal database. This allows a faster symbol search algorithm that provides noticeably faster lookup performance for  large projects.

-k     ``Kernel Mode'', turns off the use of the default include dir (usually /usr/include)  when  building the database, since kernel source trees generally do not use it.

-d     Do not update the cross-reference.

<vim plugin>
$ cd ~/.vim/plugin
$ wget http://cscope.sourceforge.net/cscope_maps.vim

    " The following maps all invoke one of the following cscope search types:
"
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
아래와 같이 Ctrl + \ 에 위 단축 알파벳을 입력하면 된다.
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>

그밖에 Ctrl + space 로 찾은 결과를 새 Window에서 볼 수 있으며,
nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>

Ctrl + space + space 로 Vertical Split도 가능하다.
nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
Posted by neodelicious
|

srcexpl.vim

vim_plugin.tgz


편한 IDE가 많겠지만 개인적으로 Linux의 Source를 Windows 에서 Source Insight로 분석하고 편집한다. Linux에서 Eclipse가 좋다고는 하지만 느린 것도 같고 UI가 불편하다.

Linux에서 source를 좀 보려고 vi를 열면서 혹시나 해서 'Linux Source Insight'로 구글에게 물어봤더니 아래 Link를 알려주었다.

http://linux.softpedia.com/get/Text-Editing-Processing/Others/Text-Editor/Vim-Plugins/Source-Explorer-39586.shtml

Source Explorer 라는 Vim plugin 인데, source code에서 함수나 변수에 커서를 가져가면 선언부를 아래에 보여준다.

아래와 같이 Vim 윗 부분에 mProfile 변수에 대해서 아랫부분에 선언부분을 보여준다. 사실 이 plugin은 ctags 의 TAG에 의존하기 때문에 ctags 기능인 ctrl + } 와 ctll + t 입력도 가능하고, ctrl + w, w 를 통해서 아래 preview 부분도 이동해서 scroll 해 볼 수 있다.


이제 위 Source Explorer 를 이용하는 방법을 알아보자.

우선 현재 system에 Vim가 설치되어 있어야 한다. 그런데 기본 Ubuntu의 경우 vim-basic이 아니라 vim-tiny가 설치되어 있다.

vi 는 아래와 같이 /etc/alternatives/vi 로 symbolic link 되어 있는데,

$ ls -l /usr/bin/vi
 /usr/bin/vi -> /etc/alternatives/vi

이를 다시 확인해 보면 아래처럼 vim.tiny 라는 것을 알 수 있다.

$ ls -l /etc/alternatives/vi
 /etc/alternatives/vi -> /usr/bin/vim.tiny

만약 이미 아래와 같이 vim.basic 이라면 상관 없지만,

$ ls -l /etc/alternatives/vi
 /etc/alternatives/vi -> /usr/bin/vim.basic

아니라면 아래처럼 vim 을 설치한다.

$ sudo apt-get install vim

참고적으로 https://lists.ubuntu.com/archives/sounder/2006-September/008662.html 에 아래와 같은 글도 있더라...

AFAIK 'vim-tiny' is a very basic build of 'vim' with most optional
features disabled, so that it is functionally pretty close to the
original 'vi'.
You could say it's "vim de-improved"...  ;-)

이제 Source Explorer 를 설치해야 한다. 직접 Link 에서 받거나 첨부파일에서 srcexpl.vim 을 받아 plugin 에 복사한다. 만약 plugin 디렉토리가 없으면 만들면 된다.

$ cp srcexpl.vim /home/jaeawon/.vim/plugin

그리고 Source Explorer 는 ctags의 TAG가 필요하기 때문에,
ctags 가 없다면 우선 설치하고,

$ sudo apt-get install exuberant-ctags
해당 source path로 이동하여 TAG 정보를 생성한다.
$ ctags -R .

끝으로 source path 안에 source 파일을 열고 :SrcExplToggle 를 입력하면 Source Explorer를 즐길(?) 수 있다.

참고적으로 srcexpl.vim 파일 맨 위에 설명도 있는데, 환경 설정을 일부 할 수 있는데, 나는 아래 것 하나만 .vimrc 에 넣어서 F8로 하도록 했다.

nmap <F8> :SrcExplToggle<CR>

그리고 Link 페이지에 있는 Taglist 와 MiniBufExpl 도 쓸만한 plugin 이다.


'Tool > editor & source viewer' 카테고리의 다른 글

cscope  (0) 2011.05.23
vim 이용하기 (내가 필요한 것만...)  (0) 2011.03.01
vim 이용  (0) 2007.12.31
Posted by neodelicious
|
아래 vim 문서를 보다가 일부 정리함....
http://www.truth.sk/vim/vimbook-OPL.pdf

<line 이동하기>
$ - 현재 line 끝으로 이동
2$ - 1 line 아래 끝으로 이동
3$ - 2 line 아래 끝으로 이동

<search - 1>
f - 현재 line에서 우측 방향으로 처음 알파벳이나 숫자 등의 위치로 이동 (예, fa 는 우측 첫 a 위치)
F - 현재 line에서 좌측 방향으로 처음 처음 알파벳이나 숫자 등의 위치로 이동 (예, Fa 는 좌측 첫 a 위치)

<search - 2>
/ 는 forward search, ? 는 backward search 이다.
n 는 현재 방향으로 반복 search, N 는 방향을 바꿔서 반복 search
'/' 입력하고 PgUp 이나 PgDn 으로 이전에 찾았던 키워드를 이용할 수 있다.

<search - 3>
:set hlsearch    - search 결과를 highlight 하도록 설정한다.
:set nohlsearch - search 결과를 highlight 하지 않도록 설정한다.
:nohlsearch      - 현재 highlight 한 search 결과에 한해서만 highlight 해제한다.

<windows>
split hello.c 으로 hello.c 을 새 window 에서 보여줄 수 있다.
vsplit 으로 vertical 하게 새 window를 보여줄 수도 있다.
split, vsplit은 각각 sp, vs으로 약자로 이용할 수 있다.
ctrl-w,w 로써 두 split window 사이에 커서를 옮겨다닐 수 있다

<programmer - 1>
>> 혹은 << 로 우측 혹은 좌측으로 shift 할 수 있다.
이때 간격 기본은 8이며 이를 :set shiftwidth=4 처럼 변경할 수 있다.

<programmer - 2>
% 는 {} () [] 와 같이 짝이 되는 행을 찾아 준다.
예를 들어 { 가 있는 행에서 % 하면 짝이 되는 } 가 있는 행으로 이동한다.
>% 혹은 >i{ 는 {} 포함 혹은 미포함하여 indentation을 맞추는데 이용한다.

'Tool > editor & source viewer' 카테고리의 다른 글

cscope  (0) 2011.05.23
Source Explorer - Vim 에서 Source Insight 따라잡기  (0) 2011.03.01
vim 이용  (0) 2007.12.31
Posted by neodelicious
|
android 내부를 좀 공부하려고 source를 받으려고 했는데, 다 받으려면 시간이 너무 오래 걸린다. 그래서 이번에는 framework direcotry만 받아봤다.

repo 가 없으면 우선  repo 부터 받는다.
curl http://android.git.kernel.org/repo > ./repo
chmod a+x ./repo

디렉토리를 하나 만들고 repo를 이용해서 repository 정보를 가져온다.
mkdir android.repo
cd android.repo
../repo init -u git://android.git.kernel.org/platform/manifest.git

프로젝트 이름 없이 repo sync 를 하면 모든 프로젝트 소스를 다운로드 하는데, 나는 framewors/base 만 받고자 한다. 이게 사실 core 이고 다른 것까지 받으면 시간이 너무 오래 걸린다. 물론 build를 하려면 전체 다 받아야 한다.
../repo sync frameworks/base

프로젝트 이름은 project.list 파일에서 알 수 있다.
cat .repo/project.list
참고적으로 frameworks/base 는 git로 관리하고 있다. 그런데 .git 에 DB에 전체 소스까지 담고 있는데, 330MB를 1.4MB 로 담고 있다니... 덜덜...

$ du -sh ./frameworks/base/
336M    ./frameworks/base/
$ du -sh ./frameworks/base/.git/
1.4M    ./frameworks/base/.git/


Posted by neodelicious
|

git commit 복구하기

Tool/git 2010. 12. 8. 01:26
git를 사용하면서 과감히 commit을 삭제할 때가 있는데, 때로는 이걸 복구해야 할 때가 있다.
git reset --hard 혹은 git branch -D 를 실수로 했을 때가 그 대표적 예일 것이다.

결론부터 얘기하면 git reset --hard에 대해서 다음과 같이 복구할 수 있고,
$ git reset --hard HEAD@{1}
git branch -D에 대해서 다음과 같이 복구할 수 있다.
$ git branch <new branch> HEAD@{1}
=> $ git branch mybranch HEAD@{1}

사실상 git branch -D 는 실행 직후 아래와 같은 log를 참고하여
Deleted branch temp (was c64b6d0).
아래와 같이 복구할 수도 있다.
$ git branch <new branch> <commit>
==> $ git branch mybranch c64b6d0

이는 git 내부에 소위 쓰레기통 같은 것이 있어서 사용자가 reference를 삭제하더라도
reflog에서 30일간 reference를 유지하여 git의 garbage collection으로부터 보호하기 때문이다.
reflog는 HEAD의 commit 이동을 기록하며, 아래와 같은 명령으로 이를 확인할 수 있다.
$ git reflog
HEAD@{#}에서 #는 HEAD가 #번 이전에 reference한 commit으로 HEAD@{1}가 직전이기 때문에 위와 같이 복구할 수가 있는 것이다.

위 내용은 아래 참고 문서에서 보고 따라한 것으로
아래 문서에서는 git reset --hard를 하기 전에 git stash를 통해 임시 저장하거나,
cron과 같은 것을 이용해서 자동으로 매일 git stash 하여 저장하는 것을 추천하고 있다.

참고 : Git from the bottom up - Git from the bottom up

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|
ubuntu netbook remix를 netbook에 설치해서 사용하고 있었는데,
무심코 이번에 ubuntu 10.10으로 upgrade 하고 나서 부팅 후에 배경 그림만 나와서 당황했다.

결론적으로 unity를 설치해서 문제를 해결했는데, 그 과정을 기록한다.

terminal과 firefox를 단축키로 설정해 두었는데,
단축키로 실행할 수 있는 것으로 봐서 home 화면을 보여주는 App. 에 문제가 있을 것으로 생각했다.
terminal을 실행해서 우연히 관련 App.을 찾다가 netbook-launcher-efl 파일을 찾았다.
그리고 실했는데, 빙고~!
우측의 아이콘들이 너무 커지고 screen top의 status bar가 안 보이는 문제가 있긴 했지만 좀 해결한 느낌.

그리고 구글링을 했더니 ubuntu 10.10 netbook remix에서는 unity를 사용해서 innovative 해 졌다나;;
아무튼 terminal에서 apt-cache search unity 를 통해서 unity package가 있는 것을 확인하고,
dpkg -l unity*를 해서 설치가 안 된 것을 확인했다.
apt-get install unity로 unity를 설치한 후에 unity를 설치했더니 뭔가 되는 것 같았다.
그리고 아마도 재부팅해야 할 것 같아 재부팅 했더니 또 빙고~!

사실 이전 netbook-launcher에서는 home screen이 있어서 배경 그림을 보지 못 했는데,
이번 unity에서는 home screen이 없어서 배경 그림을 내가 원하는 사진으로 변경했다.
UI가 달라져서 좀 낯설기는 하지만 unity가 나쁘지는 않은 거 같다.

그밖에 netbook-launcher 의 실행파일 이름이 netbook-launcher-efl 이라서,
혹시나 해서 구글링 했더니 efl 기반이 맞았다. ldd도 그렇게 알려주더라.
그나저나 Ubuntu에서도 efl이 빠르다고 이용했다니, efl이 많이 퍼지려나? 음...

$ ldd /usr/bin/netbook-launcher-efl
    libeina-ver-svn-06.so.0 => /usr/lib/libeina-ver-svn-06.so.0 (0x00388000)
    libecore-ver-svn-06.so.0 => /usr/lib/libecore-ver-svn-06.so.0 (0x008f3000)
    libevas-ver-svn-06.so.0 => /usr/lib/libevas-ver-svn-06.so.0 (0x00796000)
    libecore_evas-ver-svn-06.so.0 => /usr/lib/libecore_evas-ver-svn-06.so.0 (0x00ee8000)
    libecore_x-ver-svn-06.so.0 => /usr/lib/libecore_x-ver-svn-06.so.0 (0x009b9000)
    libecore_file-ver-svn-06.so.0 => /usr/lib/libecore_file-ver-svn-06.so.0 (0x00fdb000)
    libedje-ver-svn-06.so.0 => /usr/lib/libedje-ver-svn-06.so.0 (0x001db000)
    libelementary-ver-svn-06.so.0 => /usr/lib/libelementary-ver-svn-06.so.0 (0x00110000)
    libeet.so.1 => /usr/lib/libeet.so.1 (0x0045e000)

그런데 unity로 바뀌고, unity에 대해서 구굴링 했더니 이건 mutter를 이용했다네?
mutter는 metacity + clutter 로서 clutter를 이용했다 이건데, clutter로 약간의 효과를 줬나 보다.
ldd도 clutter 쓰고 있다는 것을 알려준다.
$ ldd /usr/bin/unity
    libclutk-0.3.so.0 => /usr/lib/libclutk-0.3.so.0 (0x001aa000)
    libclutter-gtk-0.10.so.0 => /usr/lib/libclutter-gtk-0.10.so.0 (0x00d04000)

'Personal Interest > ETC' 카테고리의 다른 글

Blog Renewal (2017.07.09)  (0) 2017.07.09
체리새우 깡...  (0) 2016.02.17
neodelicious git repos  (0) 2010.07.04
홈페이지 텍스트큐브로 전환  (0) 2010.03.03
Eclipse bug in Ubuntu 9.10  (0) 2010.02.15
Posted by neodelicious
|

git 알면 편한 기능

Tool/git 2010. 11. 13. 08:29
사내 세미나로 열심히 PPT 만들었는데, 역시 가지고 나올 수 없네요.. ㅎㅎ

git 사용할 때 알면 편한 옵션 몇 개를 소개하고자 합니다.
자세한 것은 git manual이나 기타 자료를 참고하시고요 대충 어떤 용도로 쓰면 좋은지 기능 위주로 설명하고자 합니다.
퍼 가실 때는 작성자 좀 남겨주세요~ ^^; (neodelicious - 김재원)

우선 소스 파일들을 working directory, add를 통한 commit 파일 설정한 것을 index, commit 한 후에 반영된 정보를 local repo로 부르도록 하니, 참고하세요.

1. 취소하기

작업하다보면 수정한 사항에 대해서 취소하고 싶은 경우가 생기는데, 아래 방법이 유용하다.

1.1 git add 를 통해 index 에 반영한 내용 즉, add 취소
git reset 을 통해 index의 내용을 HEAD로 되돌리고, working directory는 그대로 유지한다.
$ git reset
대표적인 사용 예가 잘못 해서 git add -u 로 모든 tracked files를 add 했을 때 특정 파일만 add 취소할 때 좋다.
$ git reset <path>
i.e) $ git reset ./a.txt
다시 얘기하지만 add에 대한 취소는 reset이다. rm 이 아니다. rm을 이용하면 git tracking에서 제외하는 엄청난 결과를 초래할 수 있다.

1.2 git commit 을 통해 local repo 에 반영한 내용 즉, commit 취소
여러 가지 경우가 있을 수 있는데, 우선 수정할 경우을 알아보면 commit --amend가 있다.
직전 commit에 대한 Log를 잘못 작성해서 Log만 수정하거나,
commit 이후에 같은 내용의 변경에 대해서 새 commit을 만들지 않고 직전 commit에 합칠 경우 유용하다.
아래와 같이 git --amend 를 통해 이전 commit과 합칠 수 있다.
$ git commit --amend
$ git commit --amend -C HEAD
그밖에 직전 commit을 취소할 경우 git reset 을 통해 직전 commit을 local repo.에서 삭제할 수 있다.
이때 HEAD가 직전 commit을 가리키므로 HEAD^로 reset 하면 된다.
$ git reset --hard HEAD^
이때 주의할 것은 --hard 옵션은 working directory 의 내용에서도 직전 commit을 삭제하고, 복구할 수 없다는 것이다.
만약 local repo에서의 commit만 삭제하고 working directory는 유지하고자 한다면,
--hard 대신 --soft 혹은 --mixed 를 사용해야 한다.
--soft와 --mixed의 차이는 index에도 삭제 여부이며, --soft는 index에 유지한다.

2. 이전 상태로 복구(roll back)하기

여러 commit을 하다보면 이전 commit 상태로 돌아가고 싶은 때가 있다.
이런 개념을 소위 check out 이라고 하는데, 이전 commit 에 대해서 check out 하면 그때 상태로 working directory가 복구된다.
git를 이용할 때는 복구하고자 하는 상태 이후에 변경한 사항을 유지할 것인가에 따라  checkout  혹은 reset 를 잘 사용해야 한다.

2.1 변경 사항을 유지할 경우 checkout을 이용한다.
git checkout 에 특정 commit을 주어 해당 commit으로 working direcotory를 변경할 수 있다.
$ git checkout <commit>
단, 이때는 임시 branch 상태이므로 잠시 이용할 사항이 아니라 이 상태에서 추가적으로 commit을 하려면
임시 branch가 아니라 새 branch를 생성해야 한다.
$ git checkout -b <new branch name>
애초에 checkout 이후에 commit 할 생각이면 특정 commit 에서 새 branch를 만드는 것이 좋다.
$ git checkout -b <new branch name> <commit>
위의 경우 복구 후에 다시 변경 사항을 그대로 유지한 branch로 checkout 할 수 있다.

2.2 변경 사항을 유지 하지 않을 경우 reset 한다.
git reset 에는 --soft, --hard, --mixed 등 옵션이 많은데, working directory까지 해당 commit으로 복구하려면,
--hard를 사용하면 되는데 해당 commit 이후의 commit은 복구할 수 없으니 주의해야 한다.
$ git reset --hard <commit>

2.3 특정 파일만 이전 상태로 변경할 경우에도 checkout 을 한다.
git checkout 에 file을 명시하지 않고 commit을 주면 전체 commit을 반영하지만, file까지 추가하면 해당 file만 반영한다.
이때는 임시 branch를 만들지 않고 해당 file만 변경하며 필요시 git commit 하면 된다.
$ git checkout <commit> <file>

3. rebase 이용하기
rebase을 이용하면 기존 commit 에 대해서 합치고, 나누고, 순서를 바꾸는 등의 다양한 기능을 할 수 있다.
거시적으로 다른 branch와의 rebase와 현재 branch에 대한 rebase로 구분할 수 있다.

3.1 다른 branch에 대한 rebase
만약 기존의 branch에서 분리하여 새 branch에서 작업하고 있었는데,
기존 branch의 추가 commit을 새 branch에 반영하고 싶다면 merge 혹은 rebase를 해야 한다.
최종 결과의 working directory를 보면 차이가 없을 수도 있지만,
gitk 와 같은 GUI로 보면 merge 와 rebase의 차이를 확연히 볼 수 있는데,
rebase는 우선적으로 기존 branch의 commit을 모두 적용한 이후에 새 branch의 commit을 적용하는 차이가 있다.
물론 rebase도 변경 사항에 따라 merge error가 발생할 수 있다.
$ git rebase <other branch>

3.2 현재 branch에 대한 rebase
현재 branch에서의 commit 에 대해서 합치고, 나누고, 순서를 바꿀 수 있다.
이때는 -i, interactive 옵션이 필요하며, 아래와 같이 변경할 범위를 지정한 후에 변경할 수 있다.
$ git rebase -i <commit>
i.e) git rebase -i HEAD~5
위 명령을 입력하면 commit 목록이 보이며,
위에서부터 commit 을 다시 적용하게 되는데 이 순서를 변경할 수 있고,
필요에 따라 edit, reword, fixup, squash 등으로 합치거나 log를 변경할 수 있다.

'Tool > git' 카테고리의 다른 글

git commit 복구하기  (3) 2010.12.08
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|
<참고 링크>
http://blog.naver.com/hi7417?Redirect=Log&logNo=80109736417


<배우>
남 - 조승우, 류정한, 정성화
여 - 김소현

<기타>
드라마 KAIST - http://video.nate.com/181367596

<뮤지컬>

지킬 앤 하이드
조승우 - 지금 이 순간 - http://www.youtube.com/watch?v=EVpgiZP9ErI
조승우 - confrontation - http://www.youtube.com/watch?v=D7kLuLV4IN0&feature=related
류정한 - 지금 이순 간 - http://www.youtube.com/watch?v=cgR5KmeQtNg

위키드 wicked
http://www.youtube.com/watch?v=3g4ekwTd6Ig

맨 오브 라만차
류정한 - 이룰 수 없는 꿈 - The impossible dream - http://www.youtube.com/watch?v=19lnzQ82JuY&feature=related
정성화 - 이룰 수 없는 꿈 - The impossible dream - http://www.youtube.com/watch?v=rid5IpdP0og

빌리 엘리어트
영화 trailer - http://www.youtube.com/watch?v=JoiVEyCosEE
http://www.youtube.com/watch?v=QF4lVBZiWR8&feature=player_embedded
http://www.youtube.com/watch?v=_EvWIpNCRfg&feature=player_embedded

<정성화 관련>

네이버 인물 - 공채 개그맨 - 뮤지컬 배우 & 텔런트 - http://people.search.naver.com/search.naver?sm=tab_txc&where=people_profile&ie=utf8&query=%EC%A0%95%EC%84%B1%ED%99%94&os=169164




'Personal Interest > Performance, Show' 카테고리의 다른 글

뮤지컬 마이 스케어리 걸  (0) 2009.04.04
뮤지컬 기발한 자살여행  (0) 2009.03.21
뮤지컬 주유소 습격사건  (0) 2009.03.12
연극 청춘, 18대1  (0) 2009.03.01
연극 마이 퍼스트 타임  (0) 2009.02.27
Posted by neodelicious
|