본문 바로가기

COMPUTER SCIENCE

[git] rebase 처리 방법

rebase

  • squash 시킬 이전 커밋 hash 입력
git rebase -i [커밋hash]

 

  • squash 시킬 commit을 pick → squash 로 변경
    • vim이라면 :[시작line번호],[끝line번호]s/^pick/squash/g 로 바꿀 수 있음
    • commit 메시지 바꾸고 싶으면 pick → reword로 변경
    • author 바꾸고 싶으면 pick → edit로 변경 후 git commit --amend --author="New Author Name [new.author.email@example.com](<mailto:new.author.email@example.com>)" 입력
pick 7aa81b4 Feat: implement UserVarEvent
squash 795f12a fix: change number of testcases
squash 9a985d6 docs: add name_len ivar comment
squash f3b0012 test: add user_var_event test
pick 9fae431 feat: extract values by type
pick 3e51af6 test: add user_var_event tests by types
pick fc79b92 feat: modify int type for negative/positive and refactor decimal type
pick 8235c7e feat: use temporary buffer for flags and add testcases

# Rebase 66c6069..8235c7e onto 66c6069 (8 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
# .       message (or the oneline, if no original merge commit was
# .       specified); use -c <commit> to reword the commit message
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#

 

  • (1) 충돌나지 않는다면
    • 바로 commit 메시지 입력하는 창 나옴
    • 원하는 대로 메시지 수정 후 넘어가면 됨
    • commit 메시지 입력 시 Co-authored-by: [username] <useremail> 로 co-author 입력 가능
    • feat: implement UserVarEvent and add testcases Co-authored-by: xxx <xxx@xxx.com>
  • (2) 충돌 발생한다면
    • 아래와 같이 메시지 나올 것
      Auto-merging pymysqlreplication/tests/test_basic.py CONFLICT (content): Merge conflict in pymysqlreplication/tests/test_basic.py error: could not apply f8324cc... test: add test_rand_event Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply f8324cc... test: add test_rand_event
    • 직접 코드 수정 후 해당 파일 git add 필요
    • git rebase --continue 로 다음 작업 진행
    • $ git add pymysqlreplication/tests/test_basic.py $ git rebase --continue
  • git push origin [브랜치 이름] --force-with-lease 로 반영

squash

git merge --squash [브랜치]

 

반응형