수정된 파일과 추가된 파일 테스트
이전 단계에서 git show --name-status와 git diff-tree --name-status가 추가된 파일에 대해 A를 표시하는 것을 보았습니다. 이제 파일이 수정되었을 때 어떻게 동작하는지 살펴보겠습니다.
먼저, ~/project/my-time-machine 디렉토리에 있는지 확인합니다.
message.txt 파일에 다른 줄을 추가해 보겠습니다.
echo "Hello again, Future Me" >> message.txt
>> 연산자는 텍스트를 기존 파일에 추가합니다.
이제 저장소의 상태를 확인해 보겠습니다.
git status
message.txt가 수정되었다는 출력을 볼 수 있습니다.
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: message.txt
no changes added to commit (use "git add" and/or "git commit -a")
Git 은 파일이 modified (수정됨) 되었음을 올바르게 식별합니다.
이제 이 변경 사항을 스테이징해 보겠습니다.
git add message.txt
그리고 상태를 다시 확인합니다.
git status
이제 출력은 변경 사항이 스테이징되었음을 표시해야 합니다.
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: message.txt
콘텐츠를 추가했지만 Git 은 이 파일을 modified (수정됨) 파일로 추적한다는 점에 유의하세요. 파일이 이전 커밋에 이미 존재했기 때문입니다.
마지막으로, 이 변경 사항을 커밋해 보겠습니다.
git commit -m "Add another message to the future"
커밋을 확인하는 출력을 볼 수 있습니다.
[master a1b2c3d] Add another message to the future
1 file changed, 1 insertion(+)
이제 새로운 커밋이 있습니다. 최신 커밋 (HEAD) 에 git show --name-status를 사용하여 상태를 확인해 보겠습니다.
git show --name-status HEAD
출력은 다음과 유사합니다.
commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9 (HEAD -> master)
Author: Jane Doe <jane.doe@example.com>
Date: Mon Aug 7 10:05:00 2023 +0000
Add another message to the future
M message.txt
message.txt 앞에 있는 M을 확인하세요. 이는 이 커밋에서 파일이 Modified (수정됨) 되었음을 나타냅니다.
마찬가지로, git diff-tree -r --name-status HEAD를 사용하면 M 상태도 볼 수 있습니다.
A (Added, 추가됨) 와 M (Modified, 수정됨) 의 이러한 구분은 Git 에서 파일의 기록을 이해하는 데 중요합니다. A는 해당 커밋에서 파일이 생성되었음을 의미하고, M은 파일이 이전에 존재했으며 해당 내용이 변경되었음을 의미합니다.