폴더/파일 무시(.gitignore)
Git 작업폴더에 다음과 같은 이유로 Trace가 원하지 않는 파일들이 생성 될 수 있습니다.
- 임시 파일 또는 폴더
- 프로그램 부산물(자동생성)
작업폴더 최상단에 .gitignore파일을 생성한 뒤, 문서편집기로 다음과 같이 작성할 수 있습니다.
.gitignore 예제# 1. 주석: #로 시작하는 라인은 주석처리됨 # 2. 특정 파일이나 디렉터리를 무시 node_modules/ *.log *.tmp /test.txt # 루트 디렉터리의 test.txt 무시 # 3. 특정 파일은 제외하지 않음 !important.log # 4. 모든 하위 디렉터리에서 특정 패턴을 무시 **/debug.log # 모든 하위 디렉터리의 debug.log 파일 무시 build/** # build/ 및 그 하위 모든 파일/디렉터리 무시 # 5. 단일 문자 대체 config?.json # config1.json, configA.json은 무시되지만 config10.json은 무시되지 않음 # 6. 문자 세트 대체 [abc].txt # a.txt, b.txt, c.txt는 무시되지만 d.txt는 무시되지 않음
또는 다음과 같이 패턴을 지정할 수 있습니다. 패턴에 관련된 내용은 git-scm.com의 패턴 형식를 따릅니다.
패턴 | 해석 |
---|---|
빈칸 | 가독성용 띄어쓰기 허용 |
\ | (ackslash) 특수문자(\#, \ , #! ...) |
# | 코멘트 |
" | "(space) 무시 |
! | 패턴 무시 |
/ | 디렉토리 |
* | /를 제외한 모든 문자 |
? | /를 제외한 한 문자 |
[] | range notation,[a-z]: a ~ z |
** | 모든 문자 |
임시저장(stash)
stash명령을 통해서 임시 저장, 불러오기를 할 수 있습니다.
git stash 작업폴더와 HEAD와의 diff를 임시저장
git stash save "임시저장 요약" 작업폴더와 HEAD와의 diff를 임시저장(저장 요약 기록)
git stash push -m "푸쉬 요약" 파일명.. 일부 파일만 임시저장
git stash list 현재 임시저장된 목록 출력
git stash pop 임시 저장 목록의 역순으로 복원
git stash pop 1 특정 임시 저장 복원
git stash drop 임시 저장 삭제(저장 역순)
git stash drop 0 특정 임시 저장 삭제
git stash clear 모든 임시 저장 삭제
임시 이동(rebase)
잘못 commit된 큰 파일 제거
scnario5.bigfilecommit에 큰 파일을 실수로 포함했을 때, 다음과 같이 제거 할 수 있습니다.
git commit -m "commit 1"
git add bigfile
git commit -m "commit 2"
git rebase -i HEAD~2
git rm bigfile
git commit --amend
git rebase --contiune
git commit -m "commit 3"
object를 검색했을 때, 완벽히 삭제된 것을 확인 할 수 있습니다.
Hash Type File Name ------------------------------------------------------------ fb9fe5b7315e2c44992c... commit (no file) 0b670021ade053c91bf8... commit (no file) 427a43ae0e3c628c5cd2... commit (no file) fa3733c9f622c2eef5f5... tree 8fc7dce4b6829e29c4b2... blob commands.txt 60c501d9e26884b9fa7f... tree bd82809671944b3bdd62... blob commands.txt b1e56f21fc970437aaae... tree 5718f1f20d3d35715c7c... blob commands.txt
오류찾기(bisect)
scnario6.bisectbisect명령을 통해서 commit의 이력을 이진탐색으로 찾을 수 있습니다. 성공한 commit과 실패한 commit을 지정하면, bisect은 중간 commit을 자동으로 checkout 해줍니다.
테스트는 직접 진행해야 합니다. 테스트 성공시 good, 실패시 bad를 bisect으로 알려야 합니다. 후보 commit중 중간 commit으로 자동 변경됩니다. 이 작업은 더 이상 후보 commit이 없을 때까지 반복됩니다.
C:\> git log --oneline 2520f32 (HEAD -> master) edit testcase bd30e5a new testcase 19a6ee6 support multi-input 0f70963 insert new testcase 9a0d511 (tag: v1.0) import doctest 89e70d1 first commit C:\> git bisect start status: waiting for both good and bad commits C:\> git bisect bad status: waiting for good commit(s), bad commit known C:\> git bisect good v1.0 Bisecting: 1 revision left to test after this (... [19a6ee6...] support multi-input [코드가 HEAD와 v1.0중간 commit으로 자동으로 변경됨. 테스트를 수행합니다.] C:\> git bisect good Bisecting: 0 revisions left to test after this (...) [bd30e5a...] new testcase [코드가 이전 테스트와 bad의 중간 commit으로 자동으로 변경됨. 테스트를 수행합니다.] C:\> git bisect bad bd30e5a... is the first bad commit commit bd30e5a... Author: iseohyun <iseohyun@hanmail.net> Date: Wed Jan 1 20:01:38 2025 +0900 new testcase test.py | 2 ++ 1 file changed, 2 insertions(+) [이 commit이 문제라고 범인정보와 함께 알려줍니다.] [정산이 끝나면 reset을 시켜줍니다.] C:\> git bisect reset Previous HEAD position was bd30e5a new testcase Switched to branch 'master' C:\>
submodule
scnario7.submodulesubmodule은 하위 디렉터리에 다른 git repo를 포함할 수 있습니다. 수동으로 submodule의 update를 체크 할 수도 있지만, submodule을 통해 자동으로 관리할 수 있습니다.
git submodule add submodule 추가
git submodule init submodule 초기화
git submodule update submodule 업데이트
git submodule update --remote submodule 업데이트(원격)
git submodule foreach git pull submodule 모두 업데이트
git submodule foreach git checkout master submodule 모두 master로 변경
git submodule foreach git pull origin master submodule 모두 master로 pull
git submodule foreach git status submodule 상태 확인
git submodule foreach git diff submodule 변경사항 확인
git submodule foreach git add . submodule 변경사항 추가
git submodule foreach git commit -m "submodule commit" submodule commit
git submodule foreach git push submodule push
git submodule foreach git pull submodule pull
git submodule foreach git reset --hard submodule 초기화
git submodule foreach git clean -fd submodule 정리
git submodule foreach git reset --hard HEAD^ submodule 이전 commit으로 되돌리기
git submodule foreach git reset --hard HEAD@{1} submodule 이전 상태로 되돌리기
git submodule foreach git reset --hard HEAD~1 submodule 이전 상태로 되돌리기
git submodule foreach git reset --hard HEAD~2 submodule 이전 상태로 되돌리기
submodule을 포함한 repo는 clone시 submodule을 포함하지 않습니다. 자동으로 submodule을 포함하려면 다음과 같이 clone합니다.
git clone --recursive submodule을 포함한 clone