[Git] checkout, switch, restore 차이

조태산·2025년 5월 24일

처음에 Git을 사용하면 헷갈리기에, 정리만 해두려고

git checkout

기능 : branch 변경, commit 시점변경
이거 사용법은 공식문서 참조 / git checkout --help


한 명령어가 기능이 2개라, 이것 때문에 중복되고 헷갈리는 듯
Git에서도 권장하지 않아용

그래서 git 2.23버전 이후로 추가된 명령어가 ~

git switch

기능 : branch 변경

  • git switch [branch]
    branch 변경

  • git switch -c [branch]
    현재 branch에서 branch를 생성 후, 새로 생성한 branch로 이동한다.

  • git swich -c [new-branch][root-branch]
    해당 branch에서 branch를 생성 후, 새로 생성한 branch로 이동한다.

git restore

기능 : commit 시점변경

  • git restore [file-name]
    해당 파일을 HEAD 커밋으로 복원

  • git restore --source [commit-hash][file-name]
    특정 파일을 특정 커밋으로 복원

  • git restore --staged [file-name]
    Staging Area에 올라간 파일을 다시 Unstaging Area로 옮길 수 있다. (해당 파일을 HEAD 커밋으로 복원한다.)

0개의 댓글