Created
February 20, 2020 04:51
-
-
Save xodhx4/f0a7a55823f31041292f9cf62d8b4814 to your computer and use it in GitHub Desktop.
[git 자주쓰는 명령어] git에서 자주 사용하지만 헷갈리는 명령어 #git #cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# git lg 로 git 명령어 alias | |
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" | |
# staing과 work directory의 차이 | |
git diff | |
# HEAD와 Stage의 차이 | |
git diff --cached | |
# HEAD와 work directory의 차이 | |
git diff HEAD | |
# 파일을 삭제하고 이를 staging | |
git rm | |
# 실제 파일은 삭제하지 않고 delete되게 staging 한 후, 남아있는 파일은 untrack | |
git rm --cached | |
# staging과 work directory는 그대로 두고 HEAD가 가리키고 있는 branch의 가리키는 커밋을 바꾼다 | |
# 마스터에서 이 명령어 사용시 마스터가 나타내는(가리키는) 커밋이 이전 커밋으로 바뀐다 | |
git reset --soft HEAD~ | |
# work directory는 나두고 HEAD가 가리키고 있는 branch의 커밋과 staging을 바꾼다 | |
# --mixed 가 디폴트 | |
git reset HEAD~ | |
# 이를 활용한 명령어. branch는 그대로 HEAD를 가리키고 staging이 HEAD로 바뀐다 | |
# 즉 add 를 취소하는 것과 같다 | |
git reset HEAD | |
# work + index + branch 모두 바꾼다 | |
git reset --hard HEAD~ | |
# reset 명령은 정해진 순서대로 세 개의 트리를 덮어써 나가다가 옵션에 따라 지정한 곳에서 멈춘다. | |
# 1. HEAD가 가리키는 브랜치를 옮긴다. (--soft 옵션이 붙으면 여기까지) | |
# 2. Index를 HEAD가 가리키는 상태로 만든다. (--hard 옵션이 붙지 않았으면 여기까지) | |
# 3. 워킹 디렉토리를 Index의 상태로 만든다. | |
# 출처 : https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-Reset-%EB%AA%85%ED%99%95%ED%9E%88-%EC%95%8C%EA%B3%A0-%EA%B0%80%EA%B8%B0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment