Last active
February 27, 2026 10:56
-
-
Save shhommychon/f5b10014ce77549355754b11907ea400 to your computer and use it in GitHub Desktop.
내가 쓰려고 남겨놓는 깃 자주 쓰는 명령어 모음
This file contains hidden or 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
| #!/bin/bash | |
| # ================================================================================ | |
| # 1. 시간 강제 및 잔디 조작 | |
| # ================================================================================ | |
| # --date는 Author Date를, 환경 변수는 Committer Date를 바꿈. 둘 다 맞춰야 완벽함. | |
| GIT_COMMITTER_DATE="2026-02-21T14:10:00" git commit -m "update shell script" --date="2026-02-21T14:10:00" | |
| # [Windows CMD 버젼] | |
| # set GIT_COMMITTER_DATE=2026-02-21T14:10:00 && git commit -m "..." --date="2026-02-21T14:10:00" | |
| # [Windows PowerShell 버젼] | |
| # $env:GIT_COMMITTER_DATE="2026-02-21T14:10:00"; git commit -m "..." --date="2026-02-21T14:10:00" | |
| # ================================================================================ | |
| # 2. 최근 커밋 시간 수정 | |
| # ================================================================================ | |
| GIT_COMMITTER_DATE="2026-02-21T14:10:00" git commit --amend --no-edit --date="2026-02-21T14:10:00" | |
| # [Windows CMD 버젼] | |
| # set GIT_COMMITTER_DATE=2026-02-21T14:10:00 && git commit --amend --no-edit --date="2026-02-21T14:10:00" | |
| # [Windows PowerShell 버젼] | |
| # $env:GIT_COMMITTER_DATE="2026-02-21T14:10:00"; git commit --amend --no-edit --date="2026-02-21T14:10:00" | |
| # ================================================================================ | |
| # 3. Merge 전략 | |
| # ================================================================================ | |
| # --no-ff (No Fast-Forward): | |
| # - 커밋 히스토리가 하나로 합쳐지지 않고 '브랜치 들어왔음'을 선명하게 남김. | |
| git merge --no-ff <branch_name> | |
| # --no-commit: | |
| # - 머지는 수행하되 자동으로 커밋하지 않음. | |
| # - 결과물을 눈으로 직접 확인하거나 추가 수정 후 커밋하고 싶을 때 유용. | |
| git merge --no-commit <branch_name> | |
| # ================================================================================ | |
| # 4. 브랜치 삭제 | |
| # ================================================================================ | |
| # 로컬 브랜치 삭제 (병합 완료 시 -d, 강제 삭제 시 -D) | |
| git branch -d <branch_name> | |
| # 원격(Remote) 브랜치 삭제 | |
| git push origin --delete <branch_name> | |
| # ================================================================================ | |
| # 5. 리모트 동기화 (Prune) | |
| # ================================================================================ | |
| # 리모트에서 이미 삭제된 가지가 로컬 브랜치 목록(git branch -r)에 남아있을 때 청소 | |
| git fetch --prune | |
| # ================================================================================ | |
| # 6. Git Stash (★제발 파일 손으로 옮기지 말 것★) | |
| # ================================================================================ | |
| # 현재 작업물 임시 저장 (작업 중 급하게 브랜치 이동할 때) | |
| git stash | |
| # 가장 최근 저장한 stash 불러오면서 리스트에서 제거 | |
| git stash pop | |
| # 불러오기만 하고 리스트에 남겨두기 | |
| git stash apply | |
| # stash 리스트 전체 삭제 | |
| git stash clear | |
| # ================================================================================ | |
| # 7. 로컬 저장소 용량 정리 (Dangling Commits 제거) | |
| # ================================================================================ | |
| # 1. 모든 reflog 만료 (복구 지점 삭제) | |
| git reflog expire --expire=now --all | |
| # 2. 유령 객체 즉시 삭제 및 최적화 | |
| git gc --prune=now --aggressive | |
| # [주의] 원격 저장소(GitHub 등)는 이 명령어로 정리되지 않음. | |
| # 고객센터에 수동 GC를 요청하거나, 민감 데이터라면 리포지토리를 새로 파는 수밖에 없음. | |
| # ================================================================================ | |
| # 8. 대량의 파일 일괄 스테이징 (argument list too long 에러 해결) | |
| # ================================================================================ | |
| # [주의] 무식하게 몇천 개 파일 한꺼번에 add 하려고 `git add **/*.json` 같은 와일드카드 쓰지 말 것. | |
| # 쉘(zsh/bash)의 명령어 최대 길이 제한에 걸려서 'argument list too long' 에러 뿜고 뻗음. | |
| # 파일이 수만 개일 때는 반드시 find와 xargs 조합으로 시스템이 소화할 수 있게 쪼개서 넘겨야 함. | |
| # [Mac / Linux / Windows Git Bash 버젼] | |
| # find와 xargs 조합으로 시스템이 소화할 수 있게 쪼개서 넘겨야 함. | |
| # 특정 확장자(예: .json) 파일 안전하게 add (공백/특수문자 포함 파일명도 문제없음) | |
| find . -name "*.json" -print0 | xargs -0 git add | |
| # 확장자 상관없이 현재 폴더 하위 모든 파일을 에러 없이 넘기기 | |
| find . -type f -print0 | xargs -0 git add | |
| # [Windows CMD 버젼] | |
| # CMD는 find와 xargs를 지원하지 않으므로 for 루프를 사용해 개별적으로 add를 실행함. | |
| # (프롬프트에서 직접 칠 때는 %i, 배치 스크립트(.bat) 안에서 쓸 때는 %%i 사용) | |
| # for /r %i in (*.json) do git add "%i" | |
| # [Windows PowerShell 버젼] | |
| # PowerShell은 Get-ChildItem으로 객체를 찾아 파이프라인으로 넘김. | |
| # Get-ChildItem -Filter *.json -Recurse | ForEach-Object { git add $_.FullName } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment