파일의 상태

- Untracked
- Unmodified
- git에 기존에 등록이 되어있고 아무런 변경도 안된 상태
- Modified
- Staged
- 새로운 파일 또는 modified 된 파일을 git add를 하면 staged 상태가 된다.
Cheat Sheet
Branch
- 로컬 branch 생성
- git branch newbranch
또는
- git checkout -b newbranch
- 리모트 branch 생성
- git push origin newbranch
- git branch -set-upstream-to origin/newbranch
- local branch와 remote branch를 연동
- 브랜치 리스트 검색
- git branch
- git branch -r
- git branch -a
- branch 삭제
- git checkout master
- git branch —delete newbranch
또는
- git branch -D newbranch
- 변경 사항 또는 commit 이력이 있어도 제거
- Remote branch 제거
- git push origin :newbranch
stash (작업을 임시로 저장)
- 작업을 임시로 저장 (stack 형식으로)
- git stash (또는 git stash save)
- stash 목록 확인
- stash 꺼내서 적용
- git stash apply
- git stash apply [stash 이름]
* 이름에 해당하는 stash 적용 (stash가 없어지지는 않는다.)
- git stash apply --index
- --index 옵션은 staged 상태까지 적용한다. 옵션이 없으면 staged 상태가 풀린다.
- stash 적용과 제거
- stash 되돌리기
- git stash show -p | git apply -R
- 가장 최근의 stash로 패치를 만들고(git stash show -p), 거꾸로 패치를 해서 원상복귀
- git stash show -p [stash 이름] | git apply -R
Staged 상태에서 제거
- 파일을 잘못 추가해서 staging에서 제거하고 싶을 때
- git reset HEAD -- [FILE_NAME]
Revert
- git revert commit_id
- 리버트 시키는 이유, 리버트 되는 기록이 남음
- 역순으로 리버트를 해야 함
- git log -p
패치 파일 생성
- 특정 commit-id 로 파일 생성하기
- git show [commit 해시 or HEAD ]^
- ^ : 한개 전, ^^ : 두개 전, ~숫자 : (숫자) 몇개 전
- git diff commit-id^!
- commit 된 상태의 패치 생성과 적용
- git format-patch [commit-id]
- 현재 commit부터 입력한 commit 이전까지 패치를 만들어준다.
- commit 된 상태의 구간 diff를 만들때 사용
- git am [patch-file]
- 수정 중인 부분으로 패치 생성 및 적용
- git diff > patch-file
- patch -p1 < patch-file
- git diff —no-prefix > patch-file
- path-prefix 가 지워진 생태로 패치 파일 생성함
- patch -p0 < patch-file
- -p0은 file path를 생략하지 않고 적용
- -p1은 file path의 첫번째 경로를 무시하고 패치를 적용
참고