Git/Git: 정리

[Git] 작업 트리에서 파일 수정하는 방법 정리

데브마우스 2024. 1. 9. 16:12

git init을 하여 이미 test-git 디렉터리가 git 저장소로 초기화되어 있다고 가정합니다.

 

아래 명령어를 입력하여 git의 상태를 확인합니다.

git status

출력:

On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)


test-git 디렉터리에 메모장으로 test.txt를 추가하고 test를 작성였습니다.

git status

출력:

On branch main

No commits yet

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

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


git add test.txt
git status

출력:

On branch main

No commits yet

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


git commit 명령어로 커밋합니다.

git commit -m "test1"

[main (root-commit) 60fa2f1] test1
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt


git status

On branch main
nothing to commit, working tree clean


git log로 확인한 결과 파일이 커밋되신걸 확인할 수 있습니다.

user.name과 user.email은 사용자에 따라 다르게 출력될 수 있습니다.

git log

commit 60fa2f17fbce82a48457f8ff2f880e86a876acef (HEAD -> main)
Author: user.name <user.email>
Date:   Wed Jan 10 17:33:04 2024 +0900

    test1


아래 명령어를 통해서 파일 별로 스테이지에 올리는게 아닌 수정한 파일을 스테이지에 올리는 동시에 커밋까지 하는 코드입니다.

git commit -am "메시지 내용"