본문 바로가기
개발자 도전기

[Git] 주요 명령어(1) git status, add, commit -m '내용', log

by 개발하는아빠 2022. 10. 24.

Git을 이해하기 위해서는 세 가지 공간(working tree, staging area, repository)을 알아야 한다.

1. Working Tree(작업 트리) :흔히 말하는 폴더

  - add 전

2. Staging area :커밋을 실행하기 전의 저장소와 작업 트리 사이에 존재하는 공간, 인덱스(Index)라고도 함

  - add 후, commit 전

3. Repository(저장소)

  - commit 후

 

 

출처 : Git 웹사이트

 

돌아보면 쉬운 것 같은데, 처음에는 이 부분이 이해가 잘 안 됐다. 강의를 들어도 무슨 소린지 잘 모르게 코드만 따라서 작성했다. 내가 아는 상식 선에서 이해하려고 하지 말고, 새로운 상식은 머릿속에 주입하니 간단히 이해했다.

 

주요 명령어

1. git status

공식문서 설명 : Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git.0000

현재의 Head commit과 index 파일 간의 차이점을 보여준다?

파일 생성, 수정, 삭제한 경우 git add 할만한 일이 있는지를 보여주는 것으로 이해함.

 

2. add  : 작업 트리 내용을 인덱스에 등록

공식문서 설명 : This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit.

git add . // 현재 폴더의 모든 파일을 add
git add text.txt // 특정 파일(text.txt)만 add

아래 스크린샷은 git add app8.txt를 직후 git status한 결과

working tree의 변동사항을 git add '변동사항이 있는 파일명'할 경우, staging area로 이동(commit 대기 상태)

Changes to be committed:라고 쓰이면 초록색 글씨로 해당 파일명 표시됨.

 

3. git commit -m '메시지 입력' : 인덱스에 등록된 내용을 저장소로 커밋

Create a new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it

Changes to be committed에 해당되는 commit 대기 상태가 모두 커밋(commit)되어 Repository로 이동하게 됨.

 

4. git log

Shows the commit logs.

커밋의 로그를 보여준다.