커밋을 병합할 일이 있어서 예전에 배웠던 git rebase를 사용해서 커밋을 합쳐봤습니다!
git rebase -i HEAD~2
뒤에 숫자는 병합할 커밋의 개수만큼 입력하는 것이고 rebase 은 i옵션은 -interactive의 약어입니다!
병합할 커밋을 squash옵션을 넣어주고 병합될 대상을 pick해주면 됩니다
pick b test1
squash c test2
# Rebase a..c onto a
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
esc후 :wq를 하면 위와 비슷한 새로운 메시지 창이 뜨는데
(그리고 간혹 바로 메시지 창이 안뜨고 나가지는 경우가 있는데 그럴 경우엔 conflict 돼서 그런거니 git rebase --edit-todo를 통해 다시 커밋 커맨드를 수정하던가 git rebase --abort를 해서 다시 rebase를 하는걸 추천합니다! 저같은 경우도 병합을 잘못해서 conflict가 났었어요ㅠ)
여기서 쓰지 않을 커밋 메시지는 # 처리 해주면 되고 새로운 커밋 메시지로 만들 수 있습니다!
(이후 커밋 메시지를 변경하기 위해 git commit --ammend 를 따로 안해도 됨)
커밋 메시지는
https://www.conventionalcommits.org/en/v1.0.0-beta.4/#summary
Conventional Commits
A specification for adding human and machine readable meaning to commit messages
www.conventionalcommits.org
여길 참고해서 작성하였고 issues를 닫는 키워드는 여러가지 종류가 있는데
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
Linking a pull request to an issue - GitHub Docs
Note: The special keywords in a pull request description are interpreted when the pull request targets the repository's default branch. However, if the PR's base is any other branch, then these keywords are ignored, no links are created and merging the PR
docs.github.com
github docs에 잘 나와있습니다!
저같은 경우엔 커밋 마지막에 close #issue_num 을 넣었습니다!
커밋 메시지까지 다 넣으셨다면 마지막으로 git push -f 해주시면 돼요!
참고로 저는 병합이 잘됐는지 git log로 커밋 내역을 확인했지만 sourcetree도 트리 구조로 브런치나 이런걸 다 볼 수 있어서 편하니 추천합니다 ㅎㅎ (https://www.sourcetreeapp.com/)