본문 바로가기

TIL/Git & Github

[TIL][Git][CLI] GIT으로 뭘할건데? - 2. 커밋하기 ( Commits) 파일만들기

커밋에는 단계가 있다.

가장 요약해서 말하자면

1. 파일 수정하기/생성하기 -2. adding 하기 - 3.commit 하기

1) 파일 만들기  : mypractice 안에 food.txt 파일을 만들어보자

touch food.txt
git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	food.txt

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

 

 

2) adding 하기 : git add 파일이름.파일형식

git add food.txt
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   food.txt

 

3) commit 하기 : git commit 파일이름.파일형식

git commit -m "create a food file"

 commit 할 때에는 간단한 메세지를 남겨야한다. 대충 뭘 했는지 쓰면된다.

[master (root-commit) 64b7c67] create a food file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 food.txt

마스터 브렌치에 새로운 버전의 food file 이 만들어졌다. 커밋이되었다.

이렇게 해서 새로 만든  mypractice 폴더에 food.txt라는 파일을 만들어 봤다. 

 

그런데 adding 와 staging 이 뭐고 이 단계를 왜 거치는 건지 궁금할 수 있다.

그에 대해서 더 알아보자 

 

우선 작업환경의 공간과 상태를 구분하는 용어들을 보면

작업의 공간에는 working tree 와 staging area 와 .git directory(repository) 가 있고 

작업의 상태는 untracked 와 tracked 그리고 unmodifid modified와 staged 과 commit 가 있다.

 

 

파일을 만든다- 저장한다 -파일을 수정한다-파일을 staging area에 올린다-staged된 파일을 commit한다-repos에 저장된다.