git은 버전관리를 하기 위해 사용한다.
commit 내역 조회
git log all --oneline
[ branch ]
브랜치 생성
git branch <브랜치명>
특정 브랜치로 이동
git switch <브랜치명>
브랜치 merge
# master 브랜치에 <브랜치명>을 merge
git switch master
git merge <브랜치명>
merge 완료된 브랜치 삭제
git branch -d <브랜치명>
merge 안한 브랜치 삭제
git branch -D <브랜치명>
[특정 파일 되돌리기 ]
특정 파일 복구
git restore <파일명>
특정 파일을 특정 시점의 commit으로 되돌리기
git restore --source <커밋ID> <파일명>
[commit 되돌리기 ]
특정 commit 취소하기
git revert <커밋ID>
# 여러개의 commit을 취소하려면
git revert <커밋ID1> <커밋ID2>
+ vim editor가 뜨는 경우
커밋 메세지 수정을 할 경우 i를 누르고 글자수정 → esc 눌러서 나오기
→ :wq 입력하면 커밋 메세지가 저장
최근 commit 취소
git revert HEAD
특정 commit 시점으로 모든 것을 되돌리기
# 협업 시에는 사용X
git reset --hard <커밋ID>
Github
로컬 레포지토리를 원격저장소에 업로드 할 때
# 로컬 저장소 git 생성
git init
# 로컬 저장소 브랜치명이 master인 경우 main으로 변경
git branch -M main
# 변수명에 원격저장소 주소가 할당
git remote add <변수명> <원격저장소주소>
# example
git remote add origin https://github.com/kimbyeolhee/wonderingPill_ai.git
# 로컬저장소의 main 브랜치를 원격저장소에 올리기
git push -u origin main
-u : 원격저장소 주소를 기억해둠 → 나중에 git push로 동일한 기능 수행
원격저장소 clone
git clone <원격저장소주소>
pull
git pull <원격저장소주소> <브랜치명>
# example
git pull origin dev
git pull = git fetch + git merge
git fetch : 원격저장소에 있는 commit 중에 로컬에 없는 신규 commit을 가져오기
로컬 브랜치를 원격저장소에 올리기
git push <원격저장소주소> <로컬브랜치명>