💽 CICD/Git

[Git] switch/restore

heywantodo 2024. 1. 10. 10:57
728x90
반응형

[Git] switch/restore

Git 2.23에서 checkout을 대신 할 switch, restore가 도입되었다고 한다.

checkout이 대체된 이유는 하나의 명령어가 가진 기능이 너무 많기 때문이라고 한다.

 

명령어 설명
checkout Switch branches or restore working tree files
switch Switch branches
restore Restore working tree files

 

git switch

switch는 checkout에서 브랜치를 변경하는 부분만 담당한다.

git switch master

checkout의 -b 옵션처럼 -c 옵션으로 브랜치 생성 후 바로 전환이 가능하다.

git switch -c new-branch

특정 브랜치나 거밋에서 새로운 브랜치를 만들고 싶으면 브랜치 이름 뒤에 커밋을 지정해 주면 된다.

git switch -c new-branch [commit-hash]

 

git restore

restore는 워킹 트리의 파일을 복원해주는 역할을 한다.

파일의 수정 내용을 복원하려면 git checkout [파일명] 을 사용했는데

 

더 명확한 restore 명령어를 사용할 수 있다.

git restore README.md

git add를 통해서 수정 내용을 이미 stage에 넣은 경우, 다시 빼려면 git reset HEAD [파일명]을 사용했어야 했지만,

이 과정도 restore 명령어를 통해 해결이 가능하다.

git restore --staged README.md

 

참고

https://blog.outsider.ne.kr/1505

728x90
반응형