Git 명령어

song·2023년 10월 26일

Git

목록 보기
3/3

시작할 때

git init: 저장소(repository) 생성해준다

파일 현재상태를 기록

  1. git add 파일명.확장자: git add로 기록할 파일 고르기
  2. git commit -m "메시지": git add한 파일에 메시지를 작성

staging

  • git add file1 file2: 여러 파일 staging
  • git add .: 모든 파일 staging

상태확인

git status

commit 내역 확인

  • git log: 로그 내역을 보여준다
  • git log --oneline: 로그를 한줄로 보여준다

방금 commit한 내용 수정

git commit --amend -m "새로운 커밋 메시지"

branch 관련

  • git branch: 현재 branch가 무엇인지 알려주고 다른 branch들도 보여줌
  • git remote -v: remote된 주소 확인
  • git branch -a: remote, 로컬 브랜치 모두 조회
  • git branch branch명: 새로운 branch를 생성
  • git branch -d branch명: branch 삭제
  • git switch branch명: 작성한 branch로 이동
  • git switch -c branch명: 새로운 branch를 만들고 그 branch로 이동

branch 합치는 merge

  1. git switch 기준이 되는 branch명: 기준이 되는 branch로 이동
  2. git merge 합쳐질branch명

remote branch

  • git remote -v: 조회
  • git remote update: 업데이트
  • git remote add orgin 주소: 추가
  • git remote remove origin: 삭제
  • git remote rm origin: 삭제

작업 내용 취소

  • git restore 파일명: working directory에 변경 내용을 취소할 경우 (Tracked File일때)
  • git restore --staged 파일명: staging area에 변경 내용을 working directory로 되돌릴 때 (즉, staging 최소)
  • git restore --source 해시값 파일명: 특정 commit 시점으로 파일 복구하는 법

특정 commit 수정 (VSC에서 GUI로 하는 법)

  1. git rebase -i 변경할 곳 직전에 해시값
  2. pick을 edit으로 변경하고 switch to text 클릭
  3. 파일 저장하고 파일 나가기
  4. git commit --amend 입력 후 commit 변경하고 저장 후 파일 나가기
  5. git rebase --continue 입력하면 끝

이전 상태로 복원 (이력 제거)

  • git reset 해당해시값: commit 기록 삭제, working directory에 변경 사항 남음
  • git reset --soft 해당해시값: commit 기록 삭제, working directory, staging area에 변경 사항 남음
  • git reset --hard 해당해시값: commit한 시점으로 복원되면 이후 기록 모두 삭제
profile
인간은 적응의 동물

0개의 댓글