이번 포스트에서는 rebase 를 사용해서 commit 로그를 정리해보겠습니다.
시작
먼저 다음과 같이 각각의 파일을 만들고 commit 합니다.
git log 를 통해 commit 내역을 확인하면 다음과 같습니다.
로그인완료.txt 를 만드는 과정에서 여러 commit 들이 생긴것을 볼 수 있는데 이것을 깔끔하게 정리해보겠습니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex06 (master)
$ git log
commit 41d695d5c3df7c1c7930a485d530b390e3de7131 (HEAD -> master)
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:52:27 2023 +0900
로그인완료
commit e8b46f60c45443a196eba6103fd4a0f8c2391aa5
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:52:11 2023 +0900
로그인아파서퇴근
commit ce1259beb3f2baf07898e8c7cd486a625c277720
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:51:55 2023 +0900
로그인퇴근
commit 6329d4a5d45a6347c77e762c3db77dde66869ee1
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:51:33 2023 +0900
환경설정 완료
rebase
rebase 를 사용해서 로그를 정리하기 위해서는 -i 옵션을 사용해야 합니다.
git rebase -i HEAD~(찌그러뜨릴 갯수)
git rebase -i HEAD~3 을 입력하면 다음과 같이 vi 에디터가 나타납니다.
pick ce1259b 로그인퇴근
pick e8b46f6 로그인아파서퇴근
pick 41d695d 로그인완료
# Rebase 6329d4a..41d695d onto 6329d4a (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
<kspace/ex06/.git/rebase-merge/git-rebase-todo [unix] (14:54 09/01/2023)16,1 Top
<workspace/ex06/.git/rebase-merge/git-rebase-todo" [unix] 31L, 1374B
이때 i 를 누르면 입력모드로 바뀌게 되며,
rebase 를 통해 찌그러뜨릴때는 과거의 commit 방향으로 찌그러뜨려야합니다.
그러므로 '로그인아파서퇴근' 과 '로그인완료' 앞의 pick 을 s로 바꿔줍니다.
pick ce1259b 로그인퇴근
s e8b46f6 로그인아파서퇴근
s 41d695d 로그인완료
# Rebase 6329d4a..41d695d onto 6329d4a (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
<pace/ex06/.git/rebase-merge/git-rebase-todo[+] [unix] (14:54 09/01/2023)3,2 Top
-- INSERT --
입력이 완료되었으면 esc 를 눌러 입력모드에서 빠져나온뒤
:wq 를 입력해서 저장하면 다음과 같은 commit 메시지를 설정하는 vi 에디터 화면이 나타납니다.
# This is a combination of 3 commits.
# This is the 1st commit message:
로그인퇴근
# This is the commit message #2:
로그인아파서퇴근
# This is the commit message #3:
로그인완료
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Mon Jan 9 14:51:55 2023 +0900
#
# interactive rebase in progress; onto 6329d4a
# Last commands done (3 commands done):
# squash e8b46f6 로그인아파서퇴근
# squash 41d695d 로그인완료
<Desktop/git_workspace/ex06/.git/COMMIT_EDITMSG [unix] (15:01 09/01/2023)1,1 Top
<ST/Desktop/git_workspace/ex06/.git/COMMIT_EDITMSG" [unix] 30L, 945B
i 를 눌러 입력모드로 바꾸고
'로그인퇴근' 과 '로그인아파서퇴근' 이렇게 두가지 메세지를 삭제하고 저장합니다.
TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex06 (master)
$ git log
commit 5cd1de07be1a37a4c5325413bcf42913f216d710 (HEAD -> master)
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:51:55 2023 +0900
로그인완료
commit 6329d4a5d45a6347c77e762c3db77dde66869ee1
Author: jeehwan <tjtojan@naver.com>
Date: Mon Jan 9 14:51:33 2023 +0900
환경설정 완료
git log 를 통해 확인해보면 로그인완료라는 커밋만 남고 log 가 깔끔하게 정리된것을 볼 수 있습니다.
이 포스트는 유튜브에 올라온 메타코딩님의 Git 강의를 보고 정리한 내용입니다.
https://www.youtube.com/@metacoding
'Git' 카테고리의 다른 글
Git - clone 과 fetch (0) | 2023.01.03 |
---|---|
Git - github 프로젝트 push 와 pull (1) | 2023.01.03 |
Git - 3 way merge (0) | 2023.01.03 |
Git - fast forward merge (0) | 2023.01.03 |
Git - reset과 reflog를 통한 복구 (1) | 2022.12.31 |