여러 Stash 테스트
실제 시나리오에서는 여러 번 변경 사항을 stash 해야 할 수 있습니다. Git 은 여러 stash 를 허용하며, 이는 스택으로 관리됩니다. 가장 최근의 stash 는 스택의 맨 위에 있으며, stash@{0}으로 참조됩니다. 이전 stash 는 stash@{1}, stash@{2} 등입니다.
이것이 어떻게 작동하는지 확인하기 위해 다른 변경 사항 집합을 만들고 stash 해 보겠습니다.
먼저, ~/project/my-time-machine 디렉토리에 있는지 확인합니다.
cd ~/project/my-time-machine
이제 message.txt에 다른 줄을 추가해 보겠습니다.
echo "Adding a second line for another stash." >> message.txt
내용을 확인합니다.
cat message.txt
이제 세 줄이 표시되어야 합니다.
Hello, Future Me
Adding a new line for stashing.
Adding a second line for another stash.
이제 이러한 새로운 변경 사항을 stash 합니다.
git stash save "Added a second line for stashing demo"
새로운 stash 를 나타내는 출력이 표시되어야 합니다.
Saved working tree and index state On branch master: Added a second line for stashing demo
보유한 stash 목록을 보려면 git stash list 명령을 사용합니다.
git stash list
다음과 유사한 내용이 표시되어야 합니다.
stash@{0}: On master: Added a second line for stashing demo
stash@{1}: On master: Added a line for stashing demo
가장 최근의 stash("Added a second line...") 는 stash@{0}이고, 이전 stash("Added a line...") 는 stash@{1}임을 확인하십시오.
특정 stash 의 내용을 보려면 stash 식별자와 함께 git stash show -p를 사용할 수 있습니다. 예를 들어, 처음 만든 stash(stash@{1}) 를 보려면 다음을 수행합니다.
git stash show -p stash@{1}
그러면 stash@{1}의 변경 사항에 대한 diff 가 표시됩니다.
diff --git a/message.txt b/message.txt
index <some_hash>..<some_hash> 100644
--- a/message.txt
+++ b/message.txt
@@ -1 +1,2 @@
Hello, Future Me
+Adding a new line for stashing.
그리고 가장 최근의 stash(stash@{0}) 를 보려면:
git stash show -p stash@{0}
그러면 stash@{0}의 변경 사항에 대한 diff 가 표시됩니다.
diff --git a/message.txt b/message.txt
index <some_hash>..<some_hash> 100644
--- a/message.txt
+++ b/message.txt
@@ -2 +2,2 @@
Adding a new line for stashing.
+Adding a second line for another stash.
여러 stash 를 관리하고 개별적으로 내용을 검사할 수 있다는 것은 서로 다른 작업이나 실험을 병행할 때 매우 유용합니다.