기타

[Git] revert - 특정 시점으로 원복

royleej9 2021. 5. 15. 12:56

reset : 지정된 커밋 코드로 코드가 되돌아간다. reset 이후 커밋 히스토리가 삭제됨
revert : 지정된 커밋 부분으로 코드가 되돌아 가지만 커밋 히스토리에 기록됨


git revert

작업한 내용을 커밋과 push까지 한 상태에세 작업이 잘 못 되어 text.txt를 생성 했던 시점으로 원복 후 history에 원복 메세지를 기록 하고 싶을 때
-> text.txt 생성 이후 추가/수정했던 내용 삭제

History 상태


revert

각 commit 단계를 revert할때마다 revert 되었다는 메세지도 commit 됨

명령어

# git revert [원복 시점의 commit-hash-code]..head
git revert 4f9d95f5c25e5590177dba26cb6319ef580cfff0..head
git push

결과


git revert --no-commit / -n

-n 옵션을 사용하게 되면 각각의 commit된 과정을 revert 할때마다 commit을 하면서 revert메세지를 commit하지 않고 stage 상태로 추가만 시킴

명령어

# git revert -n [원복 시점의 commit-hash-code]..head
git revert -n 4f9d95f5c25e5590177dba26cb6319ef580cfff0..head
git commit -m "test.txt생성 시점까지 원복"
git push

결과

5.test-c 수정함!!! 과 test.txt 생성 시점까지 원복 중간에 revert메세지가 없음