본문 바로가기
Git

[Git] Git 명령어: 작업 상태 확인, 브랜치/커밋 이력, push 여부 확인

by clolee 2025. 4. 24.

✅ Git 명령어: 작업 상태 확인, 브랜치/커밋 이력, push 여부 확인


📌 1. 작업 상태 확인

🔹 git status

git status

📤 결과 예시 (변경/스테이징 상태 확인)

On branch feature/login
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   LoginForm.js

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
    modified:   App.css

✔️ 언제 씀: 파일을 수정했거나, 커밋 전에 확인할 때


🔹 git diff

git diff

🔍 결과 예시 (스테이징 전 변경 내용)

diff --git a/App.css b/App.css
index a84ab..e3b1b 100644
--- a/App.css
+++ b/App.css
@@ -1,4 +1,5 @@
 body {
   background-color: white;
+  font-size: 16px;
 }

✔️ 언제 씀: 커밋 전에 내가 뭘 수정했는지 한눈에 보고 싶을 때


🔹 git diff --staged

git diff --staged

→ 이미 git add로 스테이징된 변경 사항 확인


📌 2. 아직 Push하지 않은 커밋 확인

🔹 git log origin/main..HEAD --oneline

git log origin/main..HEAD --oneline

📋 결과 예시

c34a2f7  Fix: button spacing issue
3b2d891  Add: login validation

✔️ 의미: 아직 push하지 않은 내 로컬 커밋 2개가 있다는 뜻
✔️ 언제 씀: push 전에 커밋 목록 확인하고 싶을 때


🔹 git cherry -v origin/main

git cherry -v origin/main

🍒 결과 예시

+ 3b2d891 Add: login validation
+ c34a2f7 Fix: button spacing issue

✔️ 의미: +는 원격에 없는 커밋 (즉, push 안 됨)
✔️ 언제 씀: 로컬 전용 커밋만 정확히 보고 싶을 때


📌 3. 커밋 로그 확인

🔹 git log --oneline --graph --decorate --all

git log --oneline --graph --decorate --all

🌲 결과 예시 (브랜치 구조 시각화)

* f5b4d33 (HEAD -> feature/login) Add: login UI
* 3b2d891 Add: validation logic
| * 20ae892 (origin/main, main) Update: API endpoints
|/
* b1f2c1a Initial commit

✔️ 브랜치, 병합, HEAD 위치까지 한눈에 확인 가능
✔️ 실무에서 tig 없을 때 브랜치 구조 보기에 최고


📌 4. 특정 파일 누가 언제 수정했는지 추적

🔹 git blame

git blame src/LoginForm.js

👤 결과 예시

e13c123 (alice   2024-02-14 13:23:01 +0900) function handleLogin() {
c34a2f7 (bob     2024-04-15 09:10:18 +0900)   const [id, setId] = useState("");

✔️ 언제 씀: 버그 발생 시, “이 줄 누가 썼지?” 추적할 때


📌 5. 최근 HEAD 변경 이력 (되돌리기 전 필수)

🔹 git reflog

git reflog

🧭 결과 예시

b1f2c1a HEAD@{0}: rebase finished: returning to refs/heads/main
e8c3b2d HEAD@{1}: rebase: resolve conflict in LoginForm.js
3f2b1c7 HEAD@{2}: commit: fix: login typo

✔️ 언제 씀: reset, rebase, checkout 후 되돌릴 위치 찾을 때


📌 6. 브랜치 관련 상태 확인

🔹 git branch -v

git branch -v

🧾 결과 예시

* feature/login  c34a2f7 Add: login UI
  main           20ae892 Update: API endpoints

✔️ 로컬 브랜치 최신 커밋 확인


🔹 git branch -vv (추적 브랜치까지 확인)

git branch -vv

📦 결과 예시

* feature/login  c34a2f7 [origin/feature/login: ahead 2] Add: login UI
  main           20ae892 [origin/main] Update: API endpoints

✔️ ahead, behind 상태까지 보임
→ push 여부 확인 가능


✅ 요약: 실무에서 진짜 많이 쓰는 조합

상황 명령어 조합
스테이징 전 변경 확인 git status + git diff
커밋 내용 확인 git diff --staged
push 전 커밋 확인 git log origin/main..HEAD 또는 git cherry -v
브랜치 전체 흐름 보기 git log --oneline --graph --all
과거 HEAD 복구 git reflog
한 줄 변경 추적 git blame 파일명

댓글