본문 바로가기
AICC 과정 정리

Git 명령어 정리

by 미르아 2024. 12. 28.
728x90

브랜치 관련

  • 브랜치 확인
    • 로컬: git branch
    • 원격: git branch -r
  • 브랜치 생성
    • git branch <branch-name>
  • 브랜치 삭제
    • 일반 삭제: git branch -d <branch-name>
      (병합된 브랜치만 삭제 가능)
    • 강제 삭제: git branch -D <branch-name>
    • 원격 삭제: git push origin --delete <branch-name>
  • 브랜치 이름 변경
    • 현재 브랜치: git branch -m <new-branch-name>
    • 특정 브랜치: git branch -m <old-name> <new-name>

병합

  • 브랜치 병합:
    기준 브랜치로 이동 후 git merge <branch-name>
    병합 방식은 fast-forward 또는 병합 커밋 생성 가능.

변경사항 확인 (diff)

  • 작업 트리와 스테이징 영역 비교: git diff
  • 스테이징 영역과 마지막 커밋 비교: git diff --staged
  • HEAD 이후 변경사항 확인: git diff HEAD
  • 특정 파일 비교: git diff <filename>
  • 브랜치 비교: git diff <branch1> <branch2>
  • 커밋 비교: git diff <commit1> <commit2>

임시 저장 (stash)

  • 임시 저장: git stash
  • 가장 최근 임시 저장 적용 및 삭제: git stash pop
  • 가장 최근 임시 저장 적용 (삭제 X): git stash apply
  • 저장된 목록 확인: git stash list
  • 특정 임시 저장 삭제: git stash drop stash@{<번호>}
  • 모든 임시 저장 삭제: git stash clear

브랜치 이동 및 관리

  • 특정 커밋으로 이동: git checkout <commit-hash>
    (HEAD 기준: git checkout HEAD~1)
  • 브랜치 이동: git switch <branch-name>
  • 브랜치 생성 후 이동: git switch -c <branch-name>

변경사항 되돌리기

  • 작업 트리 변경사항 취소: git restore <filename>
  • 특정 커밋 기준으로 되돌리기: git restore --source <commit-hash> <filename>
  • 스테이징 해제: git restore --staged <filename>

커밋 관련

  • 커밋 삭제 (mixed): git reset <commit-hash>
    이후 커밋 내용은 작업 트리로 복구.
  • 커밋 삭제 (hard): git reset --hard <commit-hash>
    커밋 내용 완전히 삭제.
  • 특정 커밋 되돌리기: git revert <commit-hash>
    되돌린 기록을 새로운 커밋으로 남김.

원격 저장소 관리

  • 연결된 원격 저장소 확인: git remote -v
  • 원격 저장소 추가: git remote add <name> <url>
  • 원격 저장소 이름 변경: git remote rename <old-name> <new-name>
  • 원격 저장소 연결 해제: git remote remove <name>

데이터 전송

  • 원격 저장소로 푸시: git push <remote> <branch>
  • 특정 브랜치 푸시: git push <remote> <local-branch>:<remote-branch>
  • 원격 저장소에서 데이터 가져오기:
    • 병합 포함: git pull <remote> <branch>
      (fetch + merge)
    • 병합 없이 가져오기: git fetch <remote> <branch>
728x90

'AICC 과정 정리' 카테고리의 다른 글

node child python  (1) 2024.12.29
맥에서 React와 Git 설치 및 설정 가이드  (7) 2024.12.28
CSS / Animation  (2) 2024.12.27
CSS  (1) 2024.12.27
VS code 세팅  (2) 2024.12.27