Post

Git 노트

Git 사용법 및 명령어 정리

Git 노트

branch 명령어 메모

1
2
3
4
5
6
7
8
9
10
11
12
13
git branch -r # 원격 브랜치 목록 보기
git checkout -t {remote branch name} # 원격 브랜치로 체크아웃
git chechout -b {local branch name} {remote branch name} # 원격 저장소와 이름 다르게 하고 싶을 때

git branch -m <oldname> <newname> # 브랜치 이름변경 기본 문법
git branch -m <newname> # 현재 브랜치 이름 변경

git branch -d <local branch name> # local branch 삭제

git push origin --delete feature/test # 원격에서 삭제하고 싶은 타겟 브랜치 이름을 feature/test라고 가정
# git branch -d <branch name> && git push origin --delete <branch name> # local branch 삭제 및 원격 브랜치 삭제

git branch --list # 브랜치 목록 보기

clean 명령어 메모

1
2
3
git clean -f # untracked 파일 삭제
git clean -d -f # untracked 파일 삭제 -d: 디렉토리까지 삭제, -f: 강제로 삭제
git clean -d -f -x # gitignore에 등록된 파일까지 삭제

diff 명령어 메모

1
2
3
4
git diff # commit vs 수정 중인 파일 비교
git diff --cached # commit vs add된 파일 비교
git diff HEAD^ # commit vs commit 비교
git diff {branch1} {branch2} # branch1 vs branch2 비교

commit 명령어 메모

1
2
3
git commit --amend --no-edit --date "$(date)" # 마지막 Commit 날짜를 현재 날짜로 설정
git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 KST" # 마지막 Commit 날짜를 임의의 날짜로 설정
git commit -m "This is a blank commit" --allow-empty # 빈커밋 만들기

reset 명령어 메모

1
git reset --hard HEAD~n # n개의 commit 되돌리기

revert 명령어 메모

1
2
git revert <되돌리고 싶은 commit의 hash> # 개별 commit 되돌리기, revert commit이 자동으로 생성
git revert --no-commit <되돌리고 싶은 commit의 hash> # revert commit이 자동으로 생성x

##

1
2
git rm --cached <file> # file 이력 관리 취소
git rm -r --cached <folder> # folder 이력 관리 취소
This post is licensed under CC BY 4.0 by the author.