Git 및 GitHub 명령 치트 시트

15313 단어 gitgithubgitgithub
The essential Git commands every developer must know

모든 개발자가 알아야 할 필수 Git 명령



이 치트 시트는 Ultimate Git에서 다룬 모든 Git 명령을 다룹니다.
마스터리 블로그.
✓ 스냅샷 생성
✓ 검색 기록
✓ 분기 및 병합
✓ Git & GitHub를 사용한 협업
✓ 다시 쓰기 역사

The essential Git commands every developer must know

스냅샷 생성‌



저장소 초기화




git init 


스테이징 파일




git add file1.js 
# Stages a single file 

git add file1.js file2.js
# Stages multiple files 

git add *.js 
# Stages with a pattern

git add . 
# Stages the current directory and all its content


상태 보기




git status 
# Full status

git status -s 
# Short status


준비된 파일 커밋




git commit -m “Message” 
# Commits with a one-line message

git commit 
# Opens the default editor to type a long message


대기 장소 건너뛰기




git commit -am “Message”


파일 제거




git rm file1.js 
# Removes from working directory and staging area 

git rm --cached file1.js 
# Removes from staging area only


파일 이름 바꾸기 또는 이동




git mv file1.js file1.txt


단계적/단계적 변경 보기




git diff 
# Shows unstaged changes

git diff --staged 
# Shows staged changes

git diff --cached 
# Same as the above


기록 보기




git log 
# Full history

git log --oneline 
# Summary

git log --reverse 
# Lists the commits from the oldest to the newest


커밋 보기




git show 921a2ff 
# Shows the given commit

git show HEAD 
# Shows the last commit

git show HEAD~2 
# Two steps before the last commit

git show HEAD:file.js 
# Shows the version of file.js stored in the last commit


파일 언스테이징(git add 실행 취소)




git restore --staged file.js 
# Copies the last version of file.js from repo to index


로컬 변경 사항 폐기




git restore file.js 
# Copies file.js from index to working directory 


git restore file1.js file2.js 
# Restores multiple files in working directory

git restore . 
# Discards all local changes (except untracked files) 

git clean -fd 
# Removes all untracked files


파일의 이전 버전 복원




git restore --source=HEAD~2 file.js


검색 기록



The essential Git commands every developer must know

기록 보기




git log --stat 
# Shows the list of modified files

git log --patch 
# Shows the actual changes (patches)


기록 필터링




git log -3 
# Shows the last 3 entries

git log --author=“Mosh”

git log --before=“2020-08-17”

git log --after=“one week ago”

git log --grep=“GUI” 
# Commits with “GUI” in their message

git log -S“GUI” 
# Commits with “GUI” in their patches 

git log hash1..hash2 
# Range of commits


git log hash1..hash2 
# Range of commits

git log file.txt 
# Commits that touched file.txt


로그 출력 포맷




git log --pretty=format:”%an committed %H”


별칭 만들기




git config --global alias.lg “log --oneline"


커밋 보기




git show HEAD~2

git show HEAD~2:file1.txt 
# Shows the version of file stored in this commit


커밋 비교




git diff HEAD~2 HEAD 
# Shows the changes between two commits 

git diff HEAD~2 HEAD file.txt 
# Changes to file.txt only


커밋 확인




git checkout dad47ed 
# Checks out the given commit 

git checkout master
# Checks out the master branch


잘못된 커밋 찾기




git bisect start

git bisect bad 
# Marks the current commit as a bad commit 

git bisect good ca49180 
# Marks the given commit as a good commit 

git bisect reset 
# Terminates the bisect session


기여자 찾기




git shortlog


파일 기록 보기




git log file.txt 
# Shows the commits that touched file.txt

git log --stat file.txt 
# Shows statistics (the number of changes) for file.txt 

git log --patch file.txt 
# Shows the patches (changes) applied to file.txt


줄 작성자 찾기




git blame file.txt 
# Shows the author of each line in file.txt


태깅




git tag v1.0 
# Tags the last commit as v1.0 

git tag v1.0 5e7a828 
# Tags an earlier commit

git tag # Lists all the tags

git tag -d v1.0 # Deletes the given tag


분기 및 병합‌



The essential Git commands every developer must know

지점 관리




git branch bugfix 
# Creates a new branch called bugfix 

git checkout bugfix 
# Switches to the bugfix branch

git switch bugfix 
# Same as the above 

git switch -C bugfix 
# Creates and switches

git branch -d bugfix 
# Deletes the bugfix branch


지점 비교




git log master..bugfix 
# Lists the commits in the bugfix branch not in master 

git diff master..bugfix 
# Shows the summary of changes


스태싱




git stash push -m “New tax rules” 
# Creates a new stash 


git stash list 
# Lists all the stashes

git stash show stash@{1} 
# Shows the given stash

git stash show 1 
# shortcut for stash@{1}

git stash apply 1 
# Applies the given stash to the working dir

git stash drop 1 
# Deletes the given stash

git stash clear 
# Deletes all the stashes


병합




git merge bugfix 
# Merges the bugfix branch into the current branch 

git merge --no-ff bugfix 
# Creates a merge commit even if FF is possible

git merge --squash bugfix 
# Performs a squash merge

git merge --abort 
# Aborts the merge


병합된 브랜치 보기




git branch --merged 
# Shows the merged branches 

git branch --no-merged 
# Shows the unmerged branches


리베이스




git rebase master 
# Changes the base of the current branch


체리 따기




git cherry-pick dad47ed 
# Applies the given commit on the current branch


협동



The essential Git commands every developer must know

저장소 복제




git clone url


리모컨과 동기화




git fetch origin master 
# Fetches master from origin 

git fetch origin 
# Fetches all objects from origin

git fetch 
# Shortcut for “git fetch origin”

git fetch 
# Shortcut for “git fetch origin”

git pull 
# Fetch + merge

git push origin master 
# Pushes master to origin

git push 
# Shortcut for “git push origin master”


태그 공유




git push origin v1.0 
# Pushes tag v1.0 to origin 
git push origin —delete v1.0


지점 공유




git branch -r 
# Shows remote tracking branches

git branch -vv 
# Shows local & remote tracking branches 

git push -u origin bugfix 
# Pushes bugfix to origin

git push -d origin bugfix 
# Removes bugfix from origin


리모컨 관리




git remote 
# Shows remote repos

git remote add upstream url 
# Adds a new remote called upstream 

git remote rm upstream 
# Remotes upstream


다시 쓰는 역사



The essential Git commands every developer must know

커밋 취소




git reset --soft HEAD^ 
# Removes the last commit, keeps changed staged 

git reset --mixed HEAD^ 
# Unstages the changes as well

git reset --hard HEAD^ 
# Discards local changes


커밋 되돌리기




git revert 72856ea 
# Reverts the given commit

git revert HEAD~3.. 
# Reverts the last three commits 
git revert --no-commit HEAD~3..


손실된 커밋 복구




git reflog 
# Shows the history of HEAD

git reflog show bugfix 
# Shows the history of bugfix pointer


마지막 커밋 수정




git commit --amend


대화형 리베이스




git rebase -i HEAD~5


예:
  • official Git project site
  • ProGit book
  • Git command list
  • on-demand training courses
  • on-demand training courses
  • online Git course
  • git-cheat-sheet-education (github.com)
  • Git cheat sheet | Atlassian Git Tutorial

  • What is git ?

    게시물 Git and GitHub Command Cheat SheetAldinn Rocks에 처음 나타났습니다.

    좋은 웹페이지 즐겨찾기