본문 바로가기

Git

2. git add, commit, status 명령어

git status 명령어

git 의 파일 관리를 위한 3가지 영역!



working  directory : 내가 작업하는 공간

index 와 같은 임시저장소가 생긴다.

git directory : 내가 작업한 코드의 version 을 저장하는 공간



git lift cycle



$ git add <<추가할파일이름>>
// 한번에 추가하고 싶은 경우 
$ git add --all
$ git commit -m " Commit message"





git status 명령어 사용하기

➜  git-study git:(master) vi README.md
➜  git-study git:(master) ✗ git status
On branch master

Initial commit

Untracked files:
  (use "git add ..." to include in what will be committed)

	README.md

nothing added to commit but untracked files present (use "git add" to track)


README.md 파일을 생성했는데 보면 아직 add 한게 없엉... 이라고 한다 

( 그리고 친절하게도 git add ... 을 하면 커밋할 파일을 include 할 수 있다고 알려준다 )

그럼 한번 add 하면 어떤 변화가 일어나는지 보자


git add 명령어 사용하기

➜  git-study git:(master) ✗ git add README.md  
➜  git-study git:(master) ✗ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached ..." to unstage)

	new file:   README.md


README.md 파일이 "Changes to be committed" 목록에 들어왔다.



git add 명령어가 SVN 과 가장 큰차이를 두게 해주는 명령어이다.

git add 를 통해 commit 까지 가지 않아야 할 파일을 골라낼 수 있고,

git 을 여러번 해도 commit  은 한번만 함으로써 History 관리( 다른 사람들이 볼 때, 내가 볼때도! ) 도 깔끔하게 할수 있는 것이다.



git commit 명령어 사용하기

➜  git-study git:(master) ✗ git commit -m "Initial Commit"
[master (root-commit) b8985fa] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
➜  git-study git:(master) git status
On branch master
nothing to commit, working directory clean

one line message 를 남길때는 -m 옵션을 주고 메시지를 쓰면 된다. 원라인으로 하고 싶지 않은 경우 -m 옵션을 빼고 "git commit" 만 치면 vi 입력창이 뜬다. 거기서 메시지를 입력하고 wq 로 종료하면 된다. 나중에 다시 설명하겠지만 git 에서는 root-commit 를 매우 잘 다뤄야 한다. 처음 커밋칠때만 저 메시지가 뜬다. 사실 대부분은 git status, git add, git commit 정도의 명령어만 알아도 SVN 처럼 git을 사용하는 것이 가능하다.







'Git' 카테고리의 다른 글

5. Git Remote  (0) 2016.10.18
4. git branch 이해하기!  (0) 2016.10.17
[부록] git alias  (0) 2016.10.17
1. Git Init ( Git 시작 설정하기 )  (0) 2016.10.17
0. Git 강의  (0) 2016.10.07