Git Cheat Sheet

jh22j9·2021년 3월 12일

branch


git branch [branch name] #브랜치 생성

git switch [branch name] #브랜치 이동
git checkout [branch name] 

git checkout -b [branch name] #브랜치 생성 후 이동
git switch -C [branch name] 

git branch -d [branch name] #브랜치 삭제
git push origin --delete [branch name] #리모트 브랜치 삭제

git branch --move fix [branch name] #브랜치 이름 변경
git push --set-upstream [repository] [branch name] #리모트 브랜치 이름 변경

checkout


git checkout [hashcode] #해시코드에 해당하는 커밋으로 HEAD 이동

log


git log master..test #master, test 브랜치 사이의 커밋 내역 보기

merge


git merge [branch name] #현재 브랜치로 [branch name] 브랜치를 머지 
git merge --abort #머지 취소
git merge --continue #conflic 해결 후 이어서 머지 실행

rebase


git checkout [branch name] #fast-forward merge가 필요한 브랜치로 이동
git rebase master
git checkout master
git merge [branch name]

cherry-pick


git cherry-pick [hashcode] #현재 브런치로 hashcode에 해당하는 커밋의 내용만 가져오기

stash


git stash clear #stash 전체 목록 삭제
git stash branch [branch name] #가장 최근 stash를 새로운 브랜치에 적용

commit


git commit --amend -m "Add new file" #가장 최근 커밋 메시지 수정
git commit --amend #수정할 내용을 staging area에 옮긴 후 가장 최근 커밋에 반영

reset

git reset --soft HEAD^
git reset --soft HEAD~2 #아직 push하지 않은 커밋 취소 후 staged 상태로 되돌리기
git reset --hard [hashcode] #해시코드에 해당하는 이전 커밋으로 HEAD를 변경
git push -f [repository] [branch name] #HEAD가 가리키는 커밋 시점을 강제로 push하여 push 이전의 원하는 시점으로 돌아갈 수 있음 

rm

git rm --cached [file name] #원격 저장소에 있는 파일 삭제 
git commit -m 'Remove...'
git push origin [repository] [branch name] 

0개의 댓글