ZEROST's Blog

1. 배경

git에 사용법이 그리 익숙치가 않아서, branch이동이나 복구등등을 찾다보니 git checkout 기능이 switch, restore로 분리되어서 새 기능이 추가 되었다고 한다. 사유는 checkout 하나의 명령어에 기능이 많기 때문이라고 한다. 그 동안 checkout으로 사용해왔는데, 명확하기 위해서 분리했다고 하니 새로운 기능을 사용하는 것이 좋을 것 같다.

2. switch

branch 이동

$ git switch master
Switched to branch 'master'

branch HEAD기반 생성

$ git switch -c new-branch
Switched to a new branch 'new-branch'

branch 특정commit기반 생성

git switch -c new-branch3 67b7c2d
Switched to a new branch 'new-branch3'

branch Reset
※ 브랜치 리셋을 하는 기능이 있긴한데, 이게 권고되는건지는 확인필요

$ git switch --force-create new-branch   
Reset branch 'new-branch'

git-switch reference

3. restore

HEAD로 restore

$ git restore test.md

stage에 올라간 파일 제외하기

git restore --staged test.md

git-restore reference

4. 결론

git checkout보다는 switch, restore로 구분해서 사용하자. 그리고 해당 명령어에 전체 기능을 정리한게 아니기 때문에 다른 기능이 더 필요하다면 레퍼런스를 참조해서 진행하자. 기능을 하나씩 습득할때마다 그때마다 정리를 하자.

참조