git
TCP 9418
Usage
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] [--config-env=<name>=<envvar>] <command> [<args>] # agent가 실행 안 된 것 → 먼저 실행 eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
git <command>
- start a working area (see also: git help tutorial)
git clone [<options>] [–] <repo> [<dir>]: Clone a repository into a new directory–progress: force progress reporting not
git init [<options>] [<directory>]: Create an empty Git repository or reinitialize an existing one–bare: 로컬 서버에 저장소 생성.
- work on the current change (see also: git help everyday)
git add [<options>] [–] <pathspec>…: Add file contents to the indexgit mv [<options>] [–] <archive_name>: Move or rename a file, a directory, or a symlinkgit restore [<options>] [–] <archive_name>: Restore working tree filesgit rm [<options>] [–] <archive_name>: Remove files from the working tree and from the index
- examine the history and state (see also: git help revisions)
git bisect [<options>] [–] <archive_name>: Use binary search to find the commit that introduced a buggit diff [<options>] [–] <archive_name>:Show changes between commits, commit and working tree, etc diffgit grep [<options>] [–] <archive_name>: Print lines matching a patterngit log [<options>] [–] <archive_name>: Show commit logs loggit show [<options>] [–] <archive_name>: Show various types of objectsgit status [<options>] [–] <archive_name>: Show the working tree status
- grow, mark and tweak your common history
git branch [<options>] [–] <archive_name>: Record changes to the repositorygit commit [<options>] [–] <archive_name>: Join two or more development histories togethgit merge [<options>] [–] <archive_name>: Reapply commits on top of another base tipgit rebase [<options>] [–] <archive_name>: Reset current HEAD to the specified stategit reset [<options>] [–] <archive_name>: Switch branchesgit switch [<options>] [–] <archive_name>: Create, list, delete or verify a tag object signed with GPG
- collaborate (see also: git help workflows)
git fetch [<options>] [–] <archive_name>: Download objects and refs from another repositorygit pull [<options>] [–] <archive_name>: Fetch from and integrate with another repository or a local branchgit push [<options>] [–] <archive_name>: Update remote refs along with associated objects
git cat-file -p <hashcode>: SHA-1에 해당하는 객체(.git/objects/..) 내용 출력git cat-file -p <tag>: tag에 해당하는 객체(.git/objects/..) 내용 출력git cat-file commit HEAD: HEAD가 가리키는 커밋 확인git ls=file –stage: 인덱스 파일 실제 내용 확인git tag: 현재 생성된 태그 리스트git cherry-pick <commit>: 특정 커밋을 이 브랜치로 가져오기git reflog: reference log 보기git reflog show <branch>: 특정 브랜치의 레퍼런스 로그 보기git reflog -all: 모든 브랜치의 레퍼런스 로그 보기
repository
-u name,–set-upstream name: upstream 설정(원본. origin)
diff
커밋 변경 내용을 통합하여 확인
git diff [<options>] [–] <archive_name>:Show changes between commits, commit and working tree, etc–stat [branch | ragne]범위 또는 브랜치의 변경 내용 요약- range:
<commit_hash_1>..<commit_hash_2>범위의 변경 내용 요약해서 표시.HEAD~5..HEAD가장 최근 5개의 커밋 변경 내용 요약
– path: 특정파일로 한정
log
커밋 히스토리
git log [<options>] [–] <archive_name>: Show commit logs–stat: 각 커밋마다 변경된 파일 목록과 함께 파일별 수정 라인, 최종 변경요약을 보여줌–shoartstat:-stat보다 간결하게, 변경된 파일 수와 전체 추가/삭제 라인수만 보여줌–oneline: 커밋 히스토리를 한 줄씩 보여줌-p path: 특정 파일의 변경내역 확인
branch
git branch [<options>] [–] <archive_name>: Record changes to the repositorygit branch new_branch base_branch: base_branch에서 new_branch생성.–delete branch,-d branch: 로컬 브랜치 삭제
git switch branch: 해당 branch로 이동
git checkout branchcheckout(legacy)git switch –create branch: 해당 branch생성 후 이동
git checkout -b branchcheckout(legacy)git branch -f branch origin/branch: 특정 branch를 원격 origin/branch로 강제 업데이트
git rebase branchbranch(main)로 rebase.
merge
git merge [<options>] [–] branch: branch merge into this
Commit
git commit [<options>] [–] <archive_name>: Join two or more development histories togeth–allow-empty: 빈 커밋(변경사항 없음) 생성-m message: 커밋 메시지 지정–amend: 기존 커밋에 수정/추가
Push
git push [<options>] [–] <archive_name>: Update remote refs along with associated objects–set-upstream remote branch신규 생성한 로컬 브랜치를 원격(remote)에 새로운 브랜치((branch)로 푸시–all모든 브랜치 업로드
Pull
git pull [<options>] [–] <archive_name>:–ff-onlyFast Forward Only–defaultFast Forward Only–rebaserebase 재배치–all모든 브랜치
Fetch
git fetch [<options>] [–] <archive_name>: 원격 저장소의 브랜치 정보를 가져옴(로컬에 직접적인 영향은 없음). Pull 전 선행 명령어–all모든 브랜치
Stash
현재 진행상태를 임시 저장
git stash: 새로운 stash 생성
git stash push
삭제예정git stash savegit stash list: stash 확인git stash apply:git stash pop: 스태시에서 꺼내기
Config
$git config --list $git config --global -e $git config --global core.editor "code" # vscode 로 에디터 설정 $git config --global core.editor "code --wait" # 잠금 $git config --global user.name "zerotymer" $git config --global user.email "[email protected]" $git config user.name # zerotymer $git config user.email # [email protected] $git config --global core.autocrlf true # 캐리지 리턴 삭제. windows-tru, mac-input으로 설정. $ # 반영구적 인증 저장 $git config credential.helper 'cache --timeout=3600' # s단위 인증저장
Alias
git config –global alias.<alias> <command>: 별칭 설정git <alias>: 별칭 호출git config credential.helper<alias> store: 인증 정보 저장git config –list: 설정 확인git config –unset key: 설정 확인
Subversion
git svn: Subversion을 클라이언트로 사용.
Import
git fast-import: 다른 버전 관리시스템에서 데이터를 Git으로 가져옴
Reset
git reset commit-hash변경사항 되돌리기(Rollback)–soft: 마지막 커밋 취소 후 staging 상태 유지–mixed: 마지막 커밋 취소 후 파일은 working directory로 이동–hard: 마지막 커밋 및 변경사항 모두 폐기commit-hash: 특정 커밋HEAD~num: HEAD 커밋에서 num 전 커밋
Revert
git revert commit-hash이전 버전으로 돌리는 취소 커밋 생성
Worktree
git worktree add PATH BRANCH현재 저장소에 연결된 브랜치를 해당 경로에 만듦(../name등 별도 경로에 할 것)-b해당 브랜치를 생성
git worktree list현재 저장소에 연결된 worktree 확인git worktree remove PATH연결 제거git worktree prune연결정보 강제 정리
update-index
git update-index –skip-worktree PATH추적중인 파일을 작업 디렉토리에 쓰는것을 호피
Git Remote Repository Change
# Git global setup git config --global user.name "NAME" git config --global user.email "EMAIL" # Create a new repository git clone REPOSITORY cd folder git switch --create main touch README.md git add README.md git commit -m "add README" git push --set-upstream origin main # Push an existing folder cd existing_folder git init --initial-branch=main git remote add origin REPOSITORY git add . git commit -m "Initial commit" git push --set-upstream origin main # Push an existing Git repository cd existing_repo git remote rename origin old-origin git remote add origin REPOSITORY git push --set-upstream origin --all git push --set-upstream origin --tags # Remove Git remote git remote remove origin # git alias # git lg: 로그 예쁘게 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" # branch pull 기본 설정 git config --global pull.rebase false
Daemon
SubModule
프로젝트 내부의 독립된 Git 저장소. 메인 프로젝트에서 단순히 특정 커밋 SHA만 저장되고, 독립 저장소는 별도로 관리
git submodule add [<switches>…] <archive_name>git submodule init [<switches>…] <archive_name>git submodule update <archive_name>–init –recursive중첩된 서브모듈까지 전부 초기화–remote서브모듈을 원격 최신 커밋으로 갱신
git submodule foreach 'command': 모든 서브모듈에 일괄 명령 수행git submodule clone –recurse-submodules repo클론 시 자동으로 서브모듈까지 가져옴
Subtree
하나의 저장소 내부에 병합 커밋 이력은 별도로 추적
git subtree add –prefix=path repo_url repo_branch다른 repo를 특정 경로(path)로 병합–squash이력압축
git subtree pull –prefix=path repo_url repo_branch원격 변경사항 병합git subtree push –prefix=path repo_url repo_branch하위 저장소로 변경사항 푸시