GIT 커맨드 정리

Eaden·2020년 7월 5일
0

브랜치 종류

  • master, develop
  • release
  • hotfixes
  • feature/~

브랜치 생성

# develop 브랜치에서 feature/some 을 생성
git checkout -b feature/some develop
# remote 에도 생성
git push origin feature/some
git branch --set-upstream-to origin/feature/some

Commit

git add .
git commit -m '커밋 메시지'

Merge

# feature > develop (squash merge)
git checkout develop
git merge --squash feature/some
git commit -m 'feature/some 에 대한 통합 커밋 메시지'
git push

# develop > master (rebase merge)
git checkout develop
git rebase master
git checkout master
git merge develop
git push

브랜치 삭제

# local 삭제 (강제 삭제시에는 -D)
git branch -d feature/some
# remote 에 반영
git push origin :feature/some

원격 브랜치 동기화

# remote 상태 보기
git remote show origin
# local 을 remote 와 동기화
git fetch -p

원격 브랜치 내용으로 덮어쓰기 (강제 PULL)

 git fetch --all && git reset --hard origin/[원격브랜치명] && git pull origin [원격 브랜치명]

Commit 합치기 (rebase by squash)

  • commit message 를 수정하여 합치고 싶은 경우
  • commit 이력 확인 및 rebase
# commit 이력 확인
git log --oneline
# 합치고 싶은 commit 이력 개수 만큼 rebase
git rebase -i HEAD~2
  • 최초 commit 외에 나머지 commit 의 pick 을 s 로 변경
pick 004644d first commit
s ae53bdf second commit
  • wq 로 History 를 저장 후 commit 메시지 수정
  • 만약, remote 에도 반영하고자 하면
git push -f

Commit 합치기 (rebase by fixup)

  • 별도 수정없이 단순 commit 합치기
  • commit 이력 확인 및 rebase
  • 최초 commit 외에 나머지 commit 의 pick 을 f 로 변경
pick 004644d first commit
f ae53bdf second commit
  • wq 로 History 를 저장
    ('first commit' 메시지로 commit 이 합쳐짐)

Commit 되돌리기

# local 에서 되돌리기
git reset --hard HEAD~3
# remote 에 강제 반영
git push -f

특정파일을 커밋내역에서 제외하는 방법

  • 버전관리 제외
git update-index --assume-unchanged {파일 경로}
  • 다시 버전에 반영
git update-index --no-assume-unchanged {파일 경로}

특정 commit 반영 (cherry-pick)

  • 다른 브랜치의 특정 commit 만 가져오고 싶은 경우 사용
git cherry-pick 76ae30ef
  • 여러개 commit 일 경우
git cherry-pick 76ae30ef 13af32cc
  • 연속된 여러개의 commit 일 경우
git cherry-pick 76ae30ef..a022451c

작업중인 항목 임시 저장 (stash)

  • 작업중인 내용 임시로 저장하고 working directory 를 비울때 (새로운 stash 저장)
git stash
  • stash 목록 확인
git stash list
  • 임시 저장항목 불러오기 (stash 불러오기)
// 가장 최근의 stash 불러오기
git stash apply

// stash 이름 (stash@{2}) 지정 불러오기
git stash apply [stash 이름]
  • stash 제거
// 가장 최근의 stash 삭제
git stash drop

// stash 이름 (stash@{2}) 지정 불러오기
git stash drop [stash 이름]
profile
일단 기록하자!!!

1개의 댓글

comment-user-thumbnail
2020년 8월 17일
답글 달기