# 마지막 커밋 해시
git log --pretty=format:'%h' -n 1

%h 는 축약 해시 자리표시자다.1

# 유저정보
git config user.name
git config user.email

Footnotes

  1. git-scm — PRETTY FORMATS: %h — “abbreviated commit hash” ↩

#101

discard1

git checkout -- <file>

git restore <file>

git reset --hard

checkout --·restore 는 파일을 인덱스 내용으로 되돌려서 add 해둔 변경은 남고, reset --hard 는 인덱스까지 HEAD 로 맞춘다.2

리모트 브랜치 가져오기

git remote update

리모트 전체를 fetch 한다.3


Footnotes

  1. 명령어로 discard를 하려면 ↩

  2. git-restore: “By default, if --staged is given, the contents are restored from HEAD, otherwise from the index.” / git-reset --hard — “Update the index to match the new HEAD, so nothing will be staged.” ↩

  3. git-remote update — “Fetch updates for remotes or remote groups in the repository as defined by remotes.<group>.” ↩

#105

.gitignore 는 이미 추적 중인 파일에 적용되지 않는다 — 인덱스에서 빼고(--cached) 다시 add 해야 규칙이 먹는다.1

# .gitignore가 규칙이 적용되지 않을때
git rm -rf --cached .
git add .

Footnotes

  1. Git - gitignore Documentation — DESCRIPTION: “Files already tracked by Git are not affected” / NOTES: “To stop tracking a file that is currently tracked, use git rm –cached to remove the file from the index.” ↩

#189

git merge 는 공통 조상이 없는 히스토리를 기본으로 거부한다 — --allow-unrelated-histories 가 그 안전장치를 끈다.1

git remote add {alias} {url}
git fetch {alias}
git merge --allow-unrelated-histories {alias}/{branch}

Footnotes

  1. Git - git-merge Documentation: “By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently.” ↩

#202

스택 = 서로 의존하는 PR의 연쇄. 기능 브랜치는 main에서 분기하지만 스택은 부모 PR에서 분기한다 — 그래서 검토를 기다리는 동안 다음 조각을 이어서 작업할 수 있다.

병합은 스택 아래부터. 하나가 병합되면 그 위 PR의 base를 갱신해야 한다. git 기본 기능만으로도 되지만 리베이스가 계속 따라붙어서, Graphite·Sapling 같은 도구가 그 부분을 자동화한다.

#272