Git detached head

이다연·2021년 4월 19일
0

Git & GitHub

목록 보기
7/8

detached HEAD

HEAD is directly pointing to commit itself, rather than indirectly pointing through branch.

WHY use detached head?

if you want to make a new branch from past commit

  1. git checkout commitID
  2. git branch premium (creating a new branch)
  3. git checkout premium

now HEAD is pointing to a new premium branch!

git checkout

  1. HEAD points to commit
  2. points to branch

https://www.cloudbees.com/blog/git-detached-head

Diff btw git reset and checkout

From Q&A

은 HEAD를 움직이는 명령어고 reset은 branch를 움직이는 명령어라고 간단하게 기억하고 있어도 될까요..? 오개념인가요?

그렇게 생각하셔도 될 것 같습니당.
이건 대상이 무엇이냐에 따라 조금 틀려지게 됩니다.
HEAD 는 현재 브랜치의 가장 마지막 커밋을 가리키게 됩니다.
대상이 파일이 아니라면,checkout 을 하게 되면 이 HEAD가 움직이게 됩니다. reset은 HEAD 가 가리키는 브랜치를 움직이게 돼구용.

아래도 참고해보시면 좋을 것 같아요^^

git reset 커밋아이디: 커밋되지 않은 변경사항 버리거나 커밋 폐기

git reset file명: 파일 staging 취소

git checkout 커밋아이디: 커밋 되돌리기

git checkout 브랜치: bracnch 전환

git checkout 파일명: 워킹디렉토리에서 수정한 내용 취소하기(복구불가)

profile
Dayeon Lee | Django & Python Web Developer

0개의 댓글