xtring.dev

[Git] git switch, restore가 뭐야?📍 - checkout에서 switch, restore 본문

for Dev./Git | Github

[Git] git switch, restore가 뭐야?📍 - checkout에서 switch, restore

xtring 2021. 12. 9. 13:38

 

git switch, restore가 뭐야?

checkout에서 switch, restore로

 

 

Ref.

[Tech] Git 2.23.0 출시: checkout 기능 분리(switch, restore)

 

[Tech] Git 2.23.0 출시: checkout 기능 분리(switch, restore) - I'm honeymon(JiHeon Kim).

깃(Git) 2.23 버전이 지난 08월 16일 출시되었다. 가장 눈에 띄는 특징은 checkout 의 기능이 각각 switch 와 restore 로 분리된 것이다. 기존의 checkout 은 브랜치를 생성()하거나 이동하거나 복원(Restore)하는

honeymon.io

 

 

 

git checkout <branch-name>

기존에 git을 오랫동안 사용한 유저들은 checkout 명령어를 통해 브랜치를 핸들링하는데 익숙할 겁니다. 그런데 사용은 잘 하고 있어지만 최근 switch 명령어를 많이 사용하는 것을 보고 찾아 보게되었는데 checkout의 분리된 기능이더라구요. 이제는 checkout이 아닌 switch를 통해 브랜치를 핸들링해볼까합니다.

 

Git은 2019년 8월 16일 2.23.0로 업데이트하게 되면서 checkout의 기능을 switchrestore을 통해 각각 분리하였습니다. 기존의 checkout은 브랜치를 생성하거나 이동, 복원하는 용도로 사용되었습니다. 현재 21년 말에도 문제없이 checkout을 사용하고 있어 크게 분리하여 사용할 생각은 하지 않고 있었지만 이번 아티클을 작성하면서 switchrestore에 대해 알아보고 직접 사용하는 방향으로 가보려고 합니다.

 

Git 2.23 brings a new pair of experimental commands to the suite of existing ones: git switch and git restore. These two are meant to eventually provide a better interface for the well-known git checkout. The new commands intend to each have a clear separation, neatly divvying up what the many responsibilities of git checkout, as we’ll show below.
If you’ve tried to list out what’s possible with git checkout, you might have visited the documentation to figure it out. You might have seen the phrase, *
“switch branches or restore working tree files”** and scratched your head. Huh?
— Taylor Blau Highlights from Git 2.23*

"브랜치를 변경(Switch)하고 작업을 복원(Restore)한다."

 

 

 

 

switch: 브랜치를 변경한다.

switch 명령어를 통해 브랜치를 변경할 수 있습니다. 또한 기존에 없는 브랜치인 경우 생성하면서 변경도 가능합니다.

브랜치를 이동시켜봅시다. (main ⇒ develop)

git:(main) $ git switch develop
Switched to branch 'develop'
git:(develop) $

기존에 존재하지 않는 브랜치를 생성하고 변경해봅시다. 브랜치를 생성하고 변경하고자 할때는 -c 옵션을 붙여줍니다.

git:(develop) $ git switch -c feat/new-feature
Switched to branch 'feat/new-feature'
git:(feat/new-feature) $

 

 

 

 

 

restore: 작업중인 파일을 되돌린다.(복원)

작업중인 파일 중 기존 마지막 커밋의 상태로 되돌리고자 할 때는 restore을 사용합니다.

git:(feat/new-feature) $ git restore new-component.jsx

해당 명령어를 통해 변경사항을 원래 상태로 되돌릴 수 있습니다.

 

 

 

 

결론

  • switch : 브랜치를 변경(+추가)
  • restore : 변경사항 복원

checkout에서 익숙하게 사용했던 기능을 새롭게 알게된 switchrestore로 사용해봅시다.

 

 

 

 

 

 

 

 

 

반응형
Comments