상세 컨텐츠

본문 제목

[git] 되돌리기 : --amend, reset, revert

😎 지식/Git&Jira🛠️

by :Eundms 2024. 3. 18. 10:03

본문

reset

1. staging area에 올라간 파일을 unstaging 할 때 이용 (git add 취소)

2. 다른 사람간 코드가 공유되지 않는 경우 (ex - 혼자만 사용하는 브랜치)

 

 

 

git reset [commit hash] : 해당 commit으로 브랜치의 참조를 변경

git reset –-hard [commit hash] : working directory, staging area, commit 모두 reset

git reset –-mixed [commit hash] : working directory 유지, staging area, commit reset , default option

git reset –-soft [commit hash] : working directory, staging area 유지, commit reset

git reset HEAD^ : HEAD를 기준으로 직전의 commit으로 reset

git reset HEAD~[정수] : HEAD를 기준으로 정수 값 단계 전 commit으로 reset

 

git reset HEAD^1 --soft

revert

원격 저장소까지 업로드된 commit을 취소할 때 사용

왜? 커밋을 추가하는 방식으로 코드를 되돌림

 

예를 들어 아래와 같이 커밋을 작성하자

git commit -m "커밋1"
git commit -m "커밋2"
git commit -m "커밋3"
git revert [커밋1해시]  // 커밋1만 삭제된다 이후의 커밋은 그대로임

 

그러면 로그에는 아래처럼 남게 된다 

Revert "커밋1"
"커밋3"
"커밋2"
"커밋1"

 

 

git revert [commit hash1]..[commit hash2] : 해당 구간만큼 commit 되돌리기

git revert [커밋1해쉬]..[커밋2해쉬]

 

로그는 아래와 같이 남게 된다

Revert "커밋2"
Revert "커밋1"

 

git revert --no-commit [commit hash3] : revert한 결과를 stage 상태만 유지하고 commit 하지 않기 

 

git revert --no-edit [commit hash] : revert commit message 수정하지 않고 default 사용

 


--amend

commit 메시지 수정

바로 직전 commit에 변경사항을 합치고 싶을때

 

 


[참고] https://wikidocs.net/150730

 

02-06. reset(2)

>*내부 회의결과, 최근에 추가한 두 파일 `Test1.txt`과 `Test2.txt`은 필요없는 파일이라고 판단하여 삭제하기로 결정하였다. >그런데 `Test1.txt`…

wikidocs.net

https://kyounghwan01.github.io/blog/etc/git/git-reset-revert/#%E1%84%8B%E1%85%B5-%E1%84%8C%E1%85%A1%E1%86%A8%E1%84%8B%E1%85%A5%E1%86%B8%E1%84%8B%E1%85%B3%E1%86%AF-%E1%84%92%E1%85%A1%E1%84%82%E1%85%B3%E1%86%AB-%E1%84%8B%E1%85%B5%E1%84%8B%E1%85%B2

 

git reset, revert로 이전 커밋으로 돌리기

git reset, revert로 이전 커밋으로 돌리기, git, github, issue, projects, milestone

kyounghwan01.github.io

 

관련글 더보기

댓글 영역