Git 문법 맛보기

Damon Kwon·2022년 1월 22일
0

Git을 아시나요

목록 보기
1/1
post-thumbnail

깃을 좀 안쓰다보면 가끔 까먹는 내용이라, 미래의 나를 위해 정리해서 올려둬야겠다는 마음에 쓴 글이다. 간략하게 액기스만 적어뒀으니 도움이 되겠지?

Branch 조회

링크 : 리모트 브랜치 참조와 업데이트

git branch
git branch -r #원격
git branch -a #모든

# Remote branch 상태 확인 / 유효하지 않은 원격 브랜치를 참조하는 경우 등을 확인할 수 있다.
git remote show origin

Branch 전환/생성

# checkout의 디렉터리 전환 및 생성 기능이 switch 명령어로 대체됨.
git switch [branch name]

# 생성
git switch -c [branch name]

삭제

원격 브랜치 삭제

링크 : git 원격지 브랜치 삭제(delete remote branch)

git push origin --delete [branch name]

# 혹은 아래와 같이 실행
git branch -d [branch name]
git push origin [branch name]

임시 저장 : Git Stash

한 번이라도 add한 적이 있는 파일(Modified or Tracked)은 전부 Stash 대상임.

# 커밋하기 애매한거 임시저장해서 워킹 디렉터리를 깨끗하기 비움. -u로 untracked도 저장 가능.
git stash

# 임시저장된 목록 확인
git stash -l

# Stash된 내용을 워킹 디렉터리에 다시 적용 (파라미터 없으면 가장 최근 stash)
git stash apply [stash@{num}]

# Stash된 내용 삭제
git stash drop

취소

Push 취소

  1. 워킹 디렉터리에서 commit을 되돌림.
# 가장 최근의 commit 취소
git reset HEAD^

# Reflog(브랜치와 HEAD가 지난 날동안 가리킨 커밋) 목록 확인 
git reflog

# 원하는 시점으로 워킹 디렉터리를 되돌림
git reset HEAD@{number} or git reset [commit id]
  1. 되돌려진 상태에서 다시 commit함
git commit -m "Return to current commit"
  1. 원격 저장소에 강제로 push함
git push origin [branch name] -f
git push origin +master
  1. untracked 파일 삭제하기
git checkout -- *

# 혹은 아래처럼 삭제. -f: 파일, -d: 디렉터리, -x: 무시된 파일, -n: 실제론 안하고 시뮬레이션 결과
git clean -f -d -x

Git Rebase

링크 : Git - Rebase 하기

# develop은 name1, feature가 name2
git switch [branch name1]
git rebase [branch name2]

Git Submodule

git submodule update --init --recursive
[submodule "ffmpeg-ref"]
 	path = ffmpeg-ref
+	url = git@bitbucket.org:n3n_us/md300-ref-ffmpeg.git

Errors

remote: error: cannot lock ref, exists; cannot create

  • 동일한 이름의 repository가 이미 원격지에 있는 경우임.
  • 새로 만들 이름을 바꾸거나, 기존의 branch를 삭제하거나 하면 됨.

commit message 글자 수 제한

  • 80글자임 쓸 것만 쓰자

참고자료

profile
👽 DevMyong, 신입 백엔드 개발자 🌊 myong.dev@gmail.com

0개의 댓글