git checkout 커밋ID
- 커밋ID를 만든 시점으로 돌아감
- HEAD 가 이동됨
$ git log --stat
commit ~~452 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:43:16 2025 +0900
message 3
hello.txt | 1 +
hello2.txt | 1 +
2 files changed, 2 insertions(+)
commit ~~ec5
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:29:20 2025 +0900
message 2
hello.txt | 1 +
1 file changed, 1 insertion(+)
commit ~~~e312
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:21:52 2025 +0900
$ git checkout 2~~ec5
Note: switching to '2~~ec5'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 26eb89e message 2
$ git log
commit ~~a4ec5 (HEAD)
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:29:20 2025 +0900
message 2
commit ~~312
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:21:52 2025 +0900
message 1
git checkout 브랜치명
- 최신 버전으로 이동하려면 checkout 브랜치명
$ git checkout main
Previous HEAD position was 26eb89e message 2
Switched to branch 'main'
$ git log
commit 69d4907a6c21a3ef4b676d22c0dc2da5d9ef8452 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:43:16 2025 +0900
message 3
commit 26eb89e1026b4d9f0b1d171f4ff37d8db04a4ec5
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:29:20 2025 +0900
message 2
commit 2eb09a5abdf2bef1d7c119e42ec2dc70bf93e312
Author: unknown <1111@~~~~~.com>
Date: Wed Sep 3 20:21:52 2025 +0900
message 1