Updated:

1. git 커밋 수정

git rebase는 merge 명령어와 함께 한 브랜치에서 다른 브랜치로 병합할 때 사용합니다.
하지만 이전의 커밋을 수정하기 위해서도 git rebase 명령어를 활용하는데, git rebase -i [Commit 해시]라는 명령어를 사용하여 커밋 내용을 수정합니다.

커밋을 수정하기 위해서는 보통

  1. git rebase -i [Commit 해시]
  2. vim 창에서 수정할 커밋 앞의 pick -> edit
  3. git commit --amend
  4. git rebase --continue
  5. git push -f origin master

의 순으로 진행합니다.

이때 git rebase -i [Commit 해시]을 실행하면 vim 창이 열리게 되고, 시작 부분에

pick [Commit ID][Commit message]

의 식으로 나타나면 pickedit으로 수정하여 커밋 수정을 진행할 수 있습니다.


2. noop 에러

그런데 다음과 같이 noop 으로 시작하게 되면 수정할 수 없습니다.

noop

# Rebase fa103914..fa103914 onto fa103914 (1 command)
#
# 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
# u, update-ref <ref> = track a placeholder for the <ref> to be updated
#                       to this position in the new commits. The <ref> is
#                       updated at the end of the rebase
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# 여기 줄을 제거하면 해당 커밋을 잃어버립니다!
#
# However, if you remove everything, the rebase will be aborted.
#

이때 다음과 같이 커밋의 범위를 지정하면, 정상적으로 pick [Commit ID][Commit message]처럼 나타나서 해결할 수 있습니다.

git rebase -i HEAD~Number


Reference


https://git-scm.com/book/ko/v2/Git-브랜치-Rebase-하기 https://velog.io/@0713vin/Git-Rebase https://stackoverflow.com/questions/6485508/git-interactive-rebase-no-commits-to-pick

Tags:

Categories:

Updated:

Leave a comment