·터미널 명령어

git rev-parse

git

쓰는 꼴

git rev-parse [--short] <rev>

HEAD나 v1.2.0^ 같은 이름을 진짜 해시로 풀어 주고 저장소 위치도 알려 줍니다 — 스크립트에서 브랜치 이름은 --abbrev-ref HEAD로 얻고, 저장소 밖에서는 오류로 끝납니다.

자주 쓰는 옵션

옵션
--short[=<n>]abbreviate the hash
--abbrev-ref HEADprint the current branch name
--show-toplevelprint the root of the working tree
--git-dirprint the path of the .git directory
--is-inside-work-treetrue or false, for scripts
--verify <rev>fail loudly if the name does not resolve

예시

git rev-parse --short HEAD

the short hash a build should stamp itself with

git rev-parse --abbrev-ref HEAD

the branch name, for a CI script

git rev-parse --show-toplevel

the repository root, wherever you are inside it

되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. git rev-parse은 무엇을 하나요?

HEAD나 v1.2.0^ 같은 이름을 진짜 해시로 풀어 주고 저장소 위치도 알려 줍니다 — 스크립트에서 브랜치 이름은 --abbrev-ref HEAD로 얻고, 저장소 밖에서는 오류로 끝납니다.

Q. 어떻게 치나요?

git rev-parse [--short] <rev> — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 6개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.

같이 보는 명령

man 페이지: man git-rev-parse