Git Undoing

Git & Github #04



Git Undoing


Restore

$ git restore file.txt #해당 파일 작업 내용 초기화
$ git restore . #working directory 파일 초기화
$ git restore --staged file.txt #staging area에 있는 파일을 working directory로 이동
$ git clean -fd #(새 파일처럼) untracked된 모든 파일 삭제

Reset

$ git reset HEAD~2 #특정 commit으로 모든 히스토리 초기화
$ git reset --mixed #히스토리에서 삭제된 commit의 작업들은 working directory로 이동
$ git reset HEAD file.txt  #staging area에 있는 파일을 working directory로 옮기기
$ git reset --soft HEAD~1 #특정 commit으로 초기화 후, 변경된 작업을 staging area로 이동
$ git reset --hard HEAD~2 #특정 commit으로 초기화 후, 변경된 작업 삭제

Revert

$ git revert hashcode #해당 commit의 변경사항을 삭제, commit 이력 남김 
$ git revert --no-commit hashcode #commit 이력 없이, 취소되는 변경사항을 staging area에 추가

Commit

$ git commit --amend -m "Title change" #최신 commit 메세지 수정
$ git amend #최신 commit 파일의 수정 내용 업데이트

rebase

$ git rebase -i hashcode(변경하고 싶은 commit 이전 hash) 
$ p #use commit
$ r #edit commit message
$ e #use commit, but stop for amending
$ s #squash commits
$ f #like squash, but discard commit message
$ d #remove commit

좋은 웹페이지 즐겨찾기