Git

git - commit한 것 되돌리기

codeManager 2022. 5. 31. 18:58
반응형

브랜치 관리를 하다보면 이미 remote branch에 커밋한 내용을 원복하고 싶은 경우가 있습니다.

 

이럴때 사용할 수 있는 git revert 명령어에 대해서 알아보겠습니다.

 

 

first라는 commit을 했는데 이것을 원복하고 싶은 경우입니다.

test@iMac demo % git log --oneline
1dc73d5 (HEAD -> master, origin/master) first
4ac8c30 init

 

마지막 커밋 1dc73d5에 대해 패치 파일을 생성합니다.

test@iMac demo % git format-patch -1 1dc73d5
0001-first.patch

 

git apply 명령어를 통해서 패치 파일을 commit합니다. (commit 내용은 1dc73d5 내용 원복)

git status를 통해서 보면 패치가 적용된 것을 볼 수 있습니다.

test@iMac demo % git apply -R 0001-first.patch
test@iMac demo % git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/main/java/com/example/demo/DemoApplication.java

 

해당 내용을 commit하고 push하면 완료.

반응형