본문 바로가기
IT 기술/개발환경_유틸 관련 팁

[git] git reset 후 commit message 재사용

by 땅뚱 2022. 1. 12.

git reset 을 하고 나서 파일을 수정한 후에, 다시 commit 을 할 때, 열심히 작성해 놓은 git reset 이전의 commit message 를 다시 불러와서 사용하고 싶은 경우가 있다.

이때 아래 명령을 사용하면 된다.

git commit --reuse-message=HEAD@{1}
또는 
git commit -C HEAD@{1}

https://stackoverflow.com/questions/16858069/git-how-to-reuse-retain-commit-messages-after-git-reset/18451418#18451418

 

Git: How to reuse/retain commit messages after 'git reset'?

As Git user I regular come across the situation, that I need to rework one or more commits in a way which do not fit into --amend or rebase -iwith fixup commits. Typically I would do something like...

stackoverflow.com

그런데, HEAD@{1} 이 무엇을 의미하는 지 궁금해졌다. git 은 자동으로 HEAD 가 가리키던 곳에 대한 history 를 가지고 있는데, HEAD@{1} 은 현재 HEAD 이전에 HEAD 가 가리키는 곳을 저장하고 있다. 이를 확인하기 위한 명령이 reflog 이다.

가장 최신은 HEAD@{0} 이고 이는 HEAD 와 동일하다.

# git reflog
734713b HEAD@{0}: commit: fixed refs handling, added gc auto, updated
d921970 HEAD@{1}: merge phedders/rdocs: Merge made by the 'recursive' strategy.
1c002dd HEAD@{2}: commit: added some blame and merge stuff

따라서 처음 명령에서 HEAD@{1} 의 '1' 값은 git 명령으로 HEAD 가 변경된 것에 따라 달라질 수 있다는 것이다. reflog 명령으로 잘 확인하고 사용하자.

 

https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-%EB%A6%AC%EB%B9%84%EC%A0%84-%EC%A1%B0%ED%9A%8C%ED%95%98%EA%B8%B0

 

Git - 리비전 조회하기

Unix나 Linux 사용 경험이 있는 경우 reflog를 Git의 Shell의 명령 히스토리 기능 버전으로 생각해볼 수 있다. 여기서 중요한 점은 오직 나의 “세션” 에서만 확인할 수 있는 내용이라는 점으로 같은

git-scm.com