본문 바로가기

TIL/Git & Github

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

food.txt 파일에 이제 직접 내용을 써보자.

 

그전에 git 과 vscode을 연동해서 사용하면 편리하기 때문에

 

vscode에서 command+shift+p 를 눌러서

제일 위에있는 셸명령 code 을 설치한다.

그럼 터미널에 code . (뛰어쓰기 된 점) 을 누르면 바로 vscode 창이 뜬다.

 

새로운 food 파일 commit 전의 상태

 

파일 commit 후의 상태

1. 파일 수정하기 make a changes

 

수정 후 저장 누르지 않은 상태

git status
On branch master
nothing to commit, working tree clean

저장 후 상태

git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   food.txt (빨간색으로 표시 unmodified라는 뜻)

no changes added to commit (use "git add" and/or "git commit -a")

위에서 working tree에 있으면서 Unmodified - save changes 상황이다.

2. 파일 staged에 올리기 : git add filename.filetype

 

git add food.txt
git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   food.txt

 

3. 파일 commit 하기 : git commit -m "commit message"

git commit -m "add type of 김밥"
[master 10e5d5b] add type of 김밥
 1 file changed, 2 insertions(+)
 git status
On branch master
nothing to commit, working tree clean

commit 후에 working tree은 비워진다.

 

4. commit 기록보기 : git log

git log
commit 10e5d5b8b2a13560796bc032cb5e5ed9bfdc5a64 (HEAD -> master)
Author:  
Date:   Wed Apr 27 13:58:46 2022 +0900

    add type of 김밥

commit cfe32de762d1384aac61116f27fd79de9725a31a
Author: 
Date:   Wed Apr 27 13:42:42 2022 +0900

    create a food file