Akashic Records

Git 상태 조회 및 변경 내용 확인 본문

Git

Git 상태 조회 및 변경 내용 확인

Andrew's Akashic Records 2023. 3. 25. 22:29
728x90

Git 저장소의 상태를 조회하고 변경 내용을 확인하는 방법은 다음과 같습니다.

  • git status: 현재 저장소의 상태를 확인합니다. 변경된 파일, 스테이징된 파일, 커밋되지 않은 변경 사항 등의 정보를 확인할 수 있습니다.

  • git diff: 작업 디렉토리와 스테이징 영역 사이의 차이를 확인합니다. 변경된 파일의 내용을 비교하고, 어떤 변경 사항이 스테이징되지 않았는지 확인할 수 있습니다.

  • git diff --staged: 스테이징 영역과 최근 커밋 사이의 차이를 확인합니다. 이를 통해 다음 커밋에 포함될 변경 사항을 미리 확인할 수 있습니다.

  • git diff <commit1> <commit2>: 두 커밋 사이의 차이를 확인합니다. 이를 통해 두 커밋 간의 변경 사항을 비교할 수 있습니다.

  • git log: 저장소의 커밋 기록을 확인합니다. 각 커밋의 해시, 작성자, 날짜, 커밋 메시지 등의 정보를 확인할 수 있습니다.

  • git show <commit>: 특정 커밋의 상세 정보와 변경 내용을 확인합니다. 이를 통해 해당 커밋의 변경 사항을 자세히 살펴볼 수 있습니다.


예시:

$ git init
$ echo "Hello, World!" > hello.txt
$ git add hello.txt
$ git commit -m "Add hello.txt"

$ git status
On branch main
nothing to commit, working tree clean

$ echo "Hello, Git!" > hello.txt

$ git diff
diff --git a/hello.txt b/hello.txt
index 1d5bc6a..2e254c1 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-Hello, World!
+Hello, Git!


$ git add hello.txt


$ git diff --staged
diff --git a/hello.txt b/hello.txt
index 1d5bc6a..2

e254c1 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-Hello, World!
+Hello, Git!

$ git commit -m "Update hello.txt"

$ git log
commit 6d0a6e4e8ea4a4d99ad6e9e6c1b8d3a3a05a60a3 (HEAD -> main)
Author: Your Name <your.email@example.com>
Date:   Mon Sep 20 14:52:03 2021 +0900

    Update hello.txt

commit 80ecb3f9a68a0fdcc8b7bcf1b35ed68ab0a2b0fd
Author: Your Name <your.email@example.com>
Date:   Mon Sep 20 14:50:35 2021 +0900

    Add hello.txt

$ git show 6d0a6e4e8ea4a4d99ad6e9e6c1b8d3a3a05a60a3
commit 6d0a6e4e8ea4a4d99ad6e9e6c1b8d3a3a05a60a3 (HEAD -> main)
Author: Your Name <your.email@example.com>
Date:   Mon Sep 20 14:52:03 2021 +0900

    Update hello.txt

diff --git a/hello.txt b/hello.txt
index 1d5bc6a..2e254c1 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-Hello, World!
+Hello, Git!

위 예시를 통해 Git 저장소의 상태를 조회하고 변경 내용을 확인하는 방법을 확인하였습니다. 이렇게 Git 명령어를 사용하여 프로젝트의 변경 이력을 추적하고 버전 관리를 수행할 수 있습니다.

728x90

'Git' 카테고리의 다른 글

Git 원격 리포지토리  (0) 2023.03.25
Git 브랜치(branch)와 병합(merge)  (0) 2023.03.25
Git 기본 명령어  (0) 2023.03.25
Git 설치 및 설정  (0) 2023.03.25
Git 버전 관리 시스템 이해  (0) 2023.03.25
Comments