Git 자주 사용하는 명령어

JS (TIL & Remind)·2022년 2월 15일
1
💡 **Git을 사용하면서 자주 사용하는 명령어들을 정리해놓은 공간입니다.**
  • add
    git add [file name]
  • 변경 사항이 있는 모든 파일 add
    git add . 
    or
    git add --all
    or
    git add -a
  • add 취소하기 (reset)
    git reset // add한 파일 전체를 Unstaged 상태로 변경한다.
    git reset HEAD [파일명] // 지정한 파일을 Unstaged 상태로 변경한다.
  • commit
    git commit -m ["커밋 메시지"]
  • 변경 사항이 있는 모든 파일 add와 동시에 commit
    git commit -am ["커밋 메시지"]
  • commit 취소하기 (reset)
    git reset --soft HEAD^ // staged 상태로 되돌린다 (add 만 한 상태)
    git reset --mixed HEAD^ // default, unstaged 상태로 되돌린다 (add 하기 전 상태)
    git reset --hard HEAD^ // 수정했던 내역까지 삭제한다.
    git reset HEAD~2 // 마지막 2개의 commit을 취소한다.
  • remote repository 등록하기
    git remote add [remote 리포지토리 주소]
  • 특정 브랜치 생성하며 remote에 push 하기
    git push origin [브랜치 이름]
  • 브랜치 생성
    git branch [브랜치 이름]
    or
    git checkout -b [브랜치 이름]
  • 브랜치 이동
    git checkout [브랜치 이름]
  • 브랜치 이름 바꾸기
    git branch -M [변경할 브랜치 이름]
  • 이전 commit과 비교하여 파일 변경 사항 확인하기 (diff)
    git diff
  • commit 로그 보기 (log)
    git log
    git log -p // 각 커밋의 diff 결과를 포함해 보여준다.
    git log -3 // 최근 3개의 log를 보여준다.
    git log --oneline // 한줄 요약
    // Q를 누르면 git log를 escape 할 수 있다.
  • 현재 브랜치에서 변경 사항 commit없이 임시로 저장하기 (stash)
    git stash // 스택에 임시로 하던 작업을 저장한다.
    git stash list // stash 목록을 확인한다.
    git stash apply // 가장 최근의 stash를 가져와 적용한다.
    git stash apply [stash 이름] // 특정 stash를 가져와 적용한다.
    git stash apply --index // stash를 가져오면서 Staged 상태였던 파일들을 다시 Staged로 만들어준다.
    git stash drop // 가장 최근의 stash를 스택에서 제거한다.
    git stash drop [stash 이름] // 특정 stash를 스택에서 제거한다.
    git stash pop // apply + drop 형태, 적용하면서 스택에서 제거한다.
    git stash show -p | git apply -R // 잘못 적용한 stash를 원래대로 되돌린다.
profile
노션에 더욱 깔끔하게 정리되어있습니다. (하단 좌측의 홈 모양 아이콘)

0개의 댓글