git add , git commit , git push "취소"

2021. 4. 26. 15:59git

728x90

git add 취소(파일 상태 unstage로 변경)

git reset HEAD [파일명]

 

git commit 취소

- 너무 일찍 commit 했을 때

- 파일 빼먹고 commit했을 때

# commit을 취소하고 해당 파일들은 staged 상태로 워킹 디렉터리에 보존
$ git reset --soft HEAD^
# commit을 취소하고 해당 파일들은 unstaged 상태로 워킹 디렉터리에 보존
$ git reset --mixed HEAD^ // 기본 옵션
$ git reset HEAD^ // 위와 동일
$ git reset HEAD~2 // 마지막 2개의 commit을 취소
# commit을 취소하고 해당 파일들은 unstaged 상태로 워킹 디렉터리에서 삭제
$ git reset --hard HEAD^

 

git push 취소 

- 자신의 local내용을 remote에 강제로 덮어쓰기를 하게 되기 때문에 주의

# 가장 최근의 commit을 취소 (기본 옵션: --mixed)
$ git reset HEAD^

# Reflog(브랜치와 HEAD가 지난 몇 달 동안에 가리켰었던 커밋) 목록 확인
$ git reflog 또는 $ git log -g

# 원하는 시점으로 워킹 디렉터리를 되돌린다.
$ git reset HEAD@{number} 또는 $ git reset [commit id]

# commit
$ git commit -m "Write commit messages"

# 경고를 무시하고 강제로 push
$ git push origin [branch name] -f
728x90