git add/commit/push 취소
2021. 4. 10. 12:40ㆍgit
728x90
git add 취소
$ git reset HEAD <file>
파일 상태를 Unstage로 변경
뒤에 파일명이 없으면 add한 파일 전체를 취소
git commit 취소
1. commit 취소 -> 해당 파일들 staged 상태로 working directory에 보존
$ git reset --soft HEAD^
2. commit 취소 -> 해당 파일들 unstaged 상태로 working directory에 보존
$ git reset --mixed HEAD^
$ git reset HEAD^
$ git reset HEAD~2 마지막 2개의 commit을 취소
3. commit취소 -> 해당 파일들 unstaged 상태, working directory에서 삭제
$ git reset --hard HEAD^
git push 취소
- local의 내용을 remote에 강제로 덮어쓰기를 하는 것이기 때문에 주의
- 되돌아간 commit 이후의 모든 commit 정보가 사라지기 때문에 주의
1. 가장 최근의 commit 취소
$ git reset HEAD^
2. 원하는 시점으로 working directory 를 되돌림
- Reflog(브랜치와 HEAD가 지난 몇 달 동안에 가리켰었던 커밋) 목록 확인
$ git reflog 또는 $ git log -g
- 원하는시점으로 working directory 되돌림
$ git reset HEAD@{number} 또는 $ git reset [commit id]
3. 되돌려진 상태에서 다시 commit
$ git commit -m "commit messages"
4. 원격 저장소에 강제 push
$ git push -f origin [branch name]
728x90
'git' 카테고리의 다른 글
[Git error] untracked working tree files would be overwritten (0) | 2021.06.06 |
---|---|
git add , git commit , git push "취소" (0) | 2021.04.26 |
git lfs (0) | 2021.04.10 |
branch 삭제 (local , remote) + 그 외 git branch 옵션들 (0) | 2021.04.01 |
git error : the following untracked working tree files would be overwritten by checkout: 파일명 (0) | 2021.03.24 |