git log --follow 실행 -- 파일
이 단계에서는 파일 이름을 변경한 경우에도 특정 파일의 히스토리를 추적하는 방법을 살펴봅니다. 이때 git log --follow 명령어가 유용하게 사용됩니다.
먼저, 프로젝트 디렉토리에 있는지 확인해 보겠습니다.
cd ~/project/my-time-machine
이제 새 파일을 만들고 내용을 추가해 보겠습니다.
echo "This is the original content." > original_file.txt
이 파일을 추가하고 커밋합니다.
git add original_file.txt
git commit -m "Add original file"
다음과 유사한 출력을 볼 수 있습니다.
[master 1a2b3c4] Add original file
1 file changed, 1 insertion(+)
create mode 100644 original_file.txt
이제 파일 이름을 변경해 보겠습니다.
git mv original_file.txt renamed_file.txt
변경 사항을 확인하기 위해 상태를 확인합니다.
git status
다음과 유사한 내용을 볼 수 있습니다.
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: original_file.txt -> renamed_file.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
message.txt
이름 변경을 커밋합니다.
git commit -m "Rename original file"
다음과 유사한 출력을 볼 수 있습니다.
[master 5d6e7f8] Rename original file
1 file changed, 0 insertions(+), 0 deletions(-)
rename original_file.txt -> renamed_file.txt (100%)
이제 git log를 사용하여 이름이 변경된 파일의 히스토리를 확인해 보겠습니다.
git log renamed_file.txt
이렇게 하면 파일 이름이 변경된 커밋만 표시됩니다. 이름 변경 전의 히스토리를 보려면 --follow 옵션을 사용해야 합니다.
git log --follow renamed_file.txt
이 명령은 파일의 히스토리를 표시하며, 이름 변경을 추적합니다. "Rename original file" 커밋과 "Add original file" 커밋을 모두 볼 수 있습니다.
git log --follow 명령어는 저장소 내에서 이동하거나 이름이 변경된 파일의 전체 히스토리를 이해해야 할 때 필수적입니다. 현재 이름에 관계없이 서로 다른 커밋에서 파일의 진화를 추적하는 데 도움이 됩니다.