적용된 변경 사항 확인 - git status
이 단계에서는 Git 의 stash 명령어가 작업 디렉토리와 어떻게 상호 작용하는지, 그리고 stash 를 적용한 후 저장소의 상태를 확인하는 방법을 살펴보겠습니다.
먼저, 프로젝트 디렉토리에 있는지 확인해 보겠습니다. 터미널을 열고 my-time-machine 디렉토리로 이동합니다.
cd ~/project/my-time-machine
이제 새로운 파일을 만들고 커밋되지 않은 변경 사항이 있는 것처럼 시뮬레이션하기 위해 일부 내용을 추가해 보겠습니다.
echo "This is a new feature." > feature.txt
echo "Adding some more content." >> message.txt
이제 새로운 파일 feature.txt를 만들고 기존 message.txt를 수정했습니다. git status를 사용하여 Git 이 이러한 변경 사항을 어떻게 보는지 확인해 보겠습니다.
git status
feature.txt가 추적되지 않고 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
Untracked files:
(use "git add <file>..." to include in what will be committed)
feature.txt
no changes added to commit (use "git add" and/or "git commit -a")
이제 이러한 변경 사항을 stash 해 보겠습니다. Stashing 은 현재 작업을 일시적으로 보류하여 불완전한 변경 사항을 커밋하지 않고 다른 작업으로 전환할 수 있도록 하는 것과 같습니다.
git stash save "Work in progress"
stash 가 저장되었음을 확인하는 출력을 볼 수 있습니다.
Saved working tree and index state On master: Work in progress
작업 디렉토리는 이제 해당 변경 사항을 만들지 않은 것처럼 깨끗해야 합니다. git status로 이를 확인할 수 있습니다.
git status
출력은 깨끗한 작업 디렉토리를 표시해야 합니다.
On branch master
nothing to commit, working tree clean
이제 방금 생성한 stash 를 적용해 보겠습니다. Stash 를 적용하면 stash 된 변경 사항이 작업 디렉토리로 다시 가져옵니다.
git stash apply
변경 사항이 적용되었음을 나타내는 출력을 볼 수 있습니다.
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
Untracked files:
(use "git add <file>..." to include in what will be committed)
feature.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9)
마지막으로, stash 를 적용한 후 작업 디렉토리의 상태를 확인하기 위해 git status를 다시 확인해 보겠습니다.
git status
출력은 stash 의 변경 사항이 이제 작업 디렉토리로 다시 돌아와 stash 하기 전과 마찬가지로 수정 및 추적되지 않은 파일로 표시됨을 보여줍니다. 이는 git stash apply가 자동으로 스테이징하거나 커밋하지 않고 변경 사항을 다시 가져온다는 것을 확인합니다.