본문 바로가기
Infra/Tools

Git 활용

by seeker00 2021. 1. 31.

branch 관련

  • git branch -m [기존 이름] [변경할 이름] : 브랜치 이름 변경
  • git branch -d [브랜치명] : 로컬 브랜치 제거
  • git push origin --delete [branchName] : 원격 브랜치 제거
  • git checkout [브랜치명] : 브랜치 변경
  • git checkout -b [브랜치명] : 브랜치 생성 및 변경

commit 관련

  • git commit -m "메세지"
  • git commit -a : add와 동시에 commit
  • git commit -am "메세지" : option -a 와 -m 을 합친 것

log 관련

  • git log
  • git log --graph

non-fast-forward 병합 관련

  1. fatal: refusing to merge unrelated histories, 원격 저장소와 로컬 저장소가 무관하고 공통된 히스토리가 없는 경우
    • git pull origin main --allow-unrelated-historiesistories (강제 병합)
  2. Automatic merge failed; fix conflicts and then commit the result.
    • 수동으로 병합을 위한 수정 처리 후 다시 commit and push

수정 이전으로 상태 되돌리기

  1. 가장 최신 commit 상태로 되돌리기
    • git reset --hard HEAD
  2. commit undo 하고 변경사항은 유지하기(구체적으로는 index 유지)
    • git reset --soft HEAD

Staging Area에서 잘못 add한 파일/폴더 제거하기

    • git rm --cached 파일/폴더명 -r