Cheat Sheet
- Linux: /kr/linux/
- CLI: /kr/linux/cli/
- locate vs type vs which vs whereis: /kr/linux/cli/locate-vs-type-vs-which-vs-whereis/
- make: /kr/linux/cli/make/
- awk: /kr/linux/cli/awk/
- find: /kr/linux/cli/find/
- grep: /kr/linux/cli/grep/
- pgrep: /kr/linux/cli/pgrep/
- ps: /kr/linux/cli/ps/
- pstree: /kr/linux/cli/pstree/
- trap: /kr/linux/cli/trap/
- xargs: /kr/linux/cli/xargs/
- Shell: /kr/linux/shell/
- BASH_SOURCE: /kr/linux/shell/bash-source/
- Redirection: /kr/linux/shell/redirection/
- Special Variables: /kr/linux/shell/special-variables/
- Interactive Shell과 Login Shell의 정의: /kr/linux/shell/interactive-login/
- Scripting Tips: /kr/linux/shell/script-tips/
- set -o vi: /kr/linux/shell/bash-vi-mode/
- Shell 실행 순서: /kr/linux/shell/process-order/
- Double Quote Expansion: /kr/linux/shell/shell-expansion/
- System Programming: /kr/linux/system-programming/
- File I/O: /kr/linux/system-programming/file-io/
- Process: /kr/linux/system-programming/process/
- Shared Libraries: /kr/linux/system-programming/shared-libraries/
- Kernel: /kr/linux/kernel/
- Go: /kr/programming/go/
- Concurrency: /kr/programming/go/concurrency/
- CSP (Communicating Sequential Processes) and Channels: /kr/programming/go/concurrency/csp/
- Channel: /kr/programming/go/concurrency/channel/
- Select: /kr/programming/go/concurrency/select/
- sync: /kr/programming/go/concurrency/sync/
- Concurrency Patterns: /kr/programming/go/concurrency/patterns/
- Goroutines and the Go Runtime: /kr/programming/go/concurrency/runtime/
- 표준 라이브러리: /kr/programming/go/std/
- os: /kr/programming/go/std/os/
- context: /kr/programming/go/std/context/
- io: /kr/programming/go/std/io/
- json: /kr/programming/go/std/json/
- net/http: /kr/programming/go/std/net-http/
- slog: /kr/programming/go/std/slog/
- testing: /kr/programming/go/std/testing/
- time: /kr/programming/go/std/time/
- Ellipsis (...): /kr/programming/go/ellipsis/
- error: /kr/programming/go/error/
- Function: /kr/programming/go/function/
- Go Tool: /kr/programming/go/tool/
- Interface: /kr/programming/go/interface/
- Map: /kr/programming/go/map/
- Package and Module: /kr/programming/go/package-module/
- Pointer: /kr/programming/go/pointer/
- Slice: /kr/programming/go/slice/
- String: /kr/programming/go/string/
- Switch: /kr/programming/go/switch/
- Comparison: /kr/programming/go/comparison/
- defaultdict: /kr/programming/python/collections/defaultdict/
- heapq: /kr/programming/python/collections/heapq/
- @cache: /kr/programming/python/cache/
- abc: /kr/programming/python/abc/
- bisect: /kr/programming/python/bisect/
- Type Hints: /kr/programming/python/type-hints/
- Passing Mechanism: /kr/programming/python/passing-mechanism/
- uv: /kr/programming/python/uv/
- *args and **kwargs: /kr/programming/python/args-kwargs/
- re: /kr/programming/python/re/
- C: /kr/programming/c/
- 포인터와 배열: /kr/programming/c/pointer/
- Syntax Basics: /kr/programming/c/syntax-basics/
- static: /kr/programming/c/static/
- Bit Manipulation: /kr/programming/c/bit-manipulation/
- C vs C++: /kr/programming/c/c-vs-cpp/
- stdatomic: /kr/programming/c/stdatomic/
- C++: /kr/programming/cpp/
- RAII (Resource Acquisition Is Initialization): /kr/programming/cpp/raii/
- Copy Elision & Move Semantics: /kr/programming/cpp/copy-elision-and-move-semantics/
- Most Vexing Parse & In-Class Initializer: /kr/programming/cpp/most-vexing-parse/
- C++ Keywords Reference: /kr/programming/cpp/keywords/
- C++ Primer: /kr/programming/cpp/primer/
- Variables and Basic Types: /kr/programming/cpp/primer/variables-and-basic-types/
- Expressions: /kr/programming/cpp/primer/expressions/
- Type Conversions and Casts: /kr/programming/cpp/primer/type-conversions-and-casts/
- Statements: /kr/programming/cpp/primer/statements/
- Functions: /kr/programming/cpp/primer/functions/
- Classes: /kr/programming/cpp/primer/classes/
- The IO Library: /kr/programming/cpp/primer/io-library/
- STL: /kr/programming/cpp/primer/stl/
- Lambda Expressions: /kr/programming/cpp/primer/lambda/
- Smart Pointers: /kr/programming/cpp/primer/smart-pointers/
- Copy Control: /kr/programming/cpp/primer/copy-control/
- Overloaded Operations and Conversions: /kr/programming/cpp/primer/operator-overloading/
- Object-Oriented Programming (OOP): /kr/programming/cpp/primer/oop/
- Templates and Generic Programming: /kr/programming/cpp/primer/templates/
- Namespaces: /kr/programming/cpp/primer/namespaces/
- Pointers to Class Member: /kr/programming/cpp/primer/pointers-to-class-member/
- Advanced: /kr/programming/cpp/advanced/
- Error Handling: /kr/programming/cpp/advanced/error-handling/
- Concurrency & Threading: /kr/programming/cpp/advanced/concurrency/
- Unit Testing: /kr/programming/cpp/advanced/unit-testing/
- 언어 별 비교: /kr/programming/comparison/
- Kubernetes: /kr/cloud-devops/kubernetes/
- Fleet: /kr/cloud-devops/kubernetes/gke/fleet/
- Kustomize vs Helm: /kr/cloud-devops/kubernetes/kustomize-vs-helm/
- API Extension: /kr/cloud-devops/kubernetes/api-extension/
- Concept: /kr/cloud-devops/kubernetes/kueue/concept/
- DRA: /kr/cloud-devops/kubernetes/dra/
- Secret Manager: /kr/cloud-devops/terraform/google-secret-manager/
- Knowledge: /kr/network/knowledge/
- PDU: /kr/network/knowledge/osi-model/
- curl: /kr/network/cli/curl/
- Concurrency Concepts: /kr/cs/concurrency-and-parallelism/concepts/
- Concurrency vs Parallelism: /kr/cs/concurrency-and-parallelism/concurrency-vs-parallelism/
- Mutex vs Atomic: /kr/cs/concurrency-and-parallelism/mutex-vs-atomic/
- Regular Expression: /kr/cs/regular-expression/
- Multiplexer vs Dispatcher: /kr/cs/multiplexer-vs-dispatcher/
- Driver and Runtime: /kr/ai-ml/gpu/driver-and-runtime/
- Serving: /kr/ai-ml/serving/
- Dotfiles: /kr/dotfiles/
- Git: /kr/dotfiles/git/
- Cheat Sheet: /kr/dotfiles/git/cheat-sheet/
- revisions: /kr/dotfiles/git/revisions/
- Submodule vs Worktree: /kr/dotfiles/git/submodule-vs-worktree/
- checkout, reset -> switch, restore: /kr/dotfiles/git/checkout-switch-restore-reset/
- rebase: /kr/dotfiles/git/rebase/
- Branching and Merging: /kr/dotfiles/git/branching-merging/
- Vim: /kr/dotfiles/vim/
- Plugin: /kr/dotfiles/vim/plugin/
- auto-pairs: /kr/dotfiles/vim/plugin/auto-pairs/
- vim-commentary: /kr/dotfiles/vim/plugin/vim-commentary/
- vim-easymotion: /kr/dotfiles/vim/plugin/vim-easymotion/
- vim-surround: /kr/dotfiles/vim/plugin/vim-surround/
- Marks: /kr/dotfiles/vim/tips/marks/
- vimrc: /kr/dotfiles/vim/vimrc/
- lf: /kr/dotfiles/lf/
## Workflow
{{< mermaid >}}
sequenceDiagram
participant SS as Stash Stack
participant WD as Workspace
(Working Directory)
participant ST as Staging Area
(Index)
participant LR as Local Repository
participant RR as Remote Repository
Note over WD, RR: Forward Flow
WD->>ST: git add ...
WD->>ST: git rm ... (≈ rm + git add)
ST->>ST: git rm --cached ... (untrack, WD 유지)
ST->>LR: git commit -m
WD->>LR: git commit -a -m
LR->>RR: git push
[] []
Note over WD, SS: Stashing Changes
WD->>SS: git stash [push] [-u] -k
ST->>SS: git stash [push] [-u]
SS-->>WD: git stash pop
SS-->>ST: git stash pop --index
Note over WD, RR: Git Restore, Switch, and Reset
ST-->>WD: git restore ...
LR-->>ST: git restore --staged ...
LR-->>WD: git restore
--source= ...
LR->>WD: git switch [-c]
LR->>LR: git reset [--soft|--mixed|--hard]
LR-->>ST: git reset [--mixed|--hard]
LR-->>WD: git reset --hard
LR-->>ST: git revert
LR->>LR:
LR-->>WD:
Note over WD, RR: Remote Sync, Rebase, and Diff
RR->>LR: git fetch []
RR->>WD: git pull [--rebase]
[] []
LR->>LR: git rebase
[]
Note over WD, ST: git diff [...]
Note over ST, LR: git diff --staged [...]
Note over WD, LR: git diff [...]
{{< /mermaid >}}
## Recommended Resources
- [Pro Git](https://git-scm.com/book): 가장 포괄적인 Git 공식 가이드.
- [Learn Git Branching](https://learngitbranching.js.org): 시각적으로 Git 명령어를 배울 수 있는 대화형 학습 사이트.
## Concepts
- **checkout**: Local Repository(LR)에 저장된 특정 commit 상태를 Workspace(WD)로 복원하거나 전환하는 행위.
- **branch & tag**: 둘 다 특정 commit을 가리키는 포인터.
- **branch**: **동적(Dynamic)** 포인터. 해당 브랜치가 체크아웃된 상태에서 새로운 커밋이 발생하면 자동으로 앞으로 이동한다.
- **tag**: **정적(Static)** 포인터. 특정 커밋에 고정되어 이동하지 않는다 (주로 릴리스 지점을 표시할 때 사용).
- `HEAD`: 현재 branch reference(attached) 또는 특정 commit(detached)을 가리키는 포인터.
- Workspace(WD)에 현재 checkout된 대상을 결정한다.
- **attached HEAD**: `HEAD`가 branch를 가리키고 있는 일반적인 상태. 커밋 시 branch 포인터가 `HEAD`와 함께 자동으로 앞으로 이동한다.
- **detached HEAD**: `HEAD`가 branch 대신 특정 commit을 직접 가리키는 상태. `git switch -c `와 같이 새 branch를 생성하지 않고 branch를 전환하면 작업 내용이 소실될 수 있다.
- `git switch `: `HEAD`가 특정 branch를 가리키도록 이동시키고, WD와 ST를 해당 상태로 갱신한다.
- **index**: staging area 또는 cache라고도 하며, 다음 commit에 포함될 변경 사항을 저장한다.
- `--staged` / `--cached`
- `git restore --staged ...`: staging area의 변경 사항을 취소한다 (LR에서 ST를 복원하며 WD는 유지).
- `git rm --cached ...`: tracking을 중지하고 WD의 파일은 유지한다.
- `git diff --staged`: staging area와 LR(HEAD)을 비교한다.
- **ref**: 특정 commit을 가리키는 이름. `.git/refs/` 디렉토리에 저장된다.
- branch: `refs/heads/`
- tag: `refs/tags/`
- remote branch: `refs/remotes//`
- **refspec**: `fetch` 및 `push` 시 로컬과 원격 저장소 간의 참조(ref)를 동기화하기 위한 매핑 규칙. 일반적으로 `[+]:` 형식을 사용한다.
- eg. `git fetch origin master:refs/remotes/origin/master`
- **staging**, **unstaging**, **discarding**
- **staging (`WD -> ST`)**: 작업 디렉토리의 변경 사항을 Staging Area로 복사한다 (`git add`).
- **unstaging (`LR -> ST`)**: `git add`를 되돌리려면 Local Repository의 상태를 Staging Area로 가져와야 한다.
- Staging 전: `v1` `v0` `v0` (WD ST LR)
- Staging 후: `v1` `v1` `v0` (WD ST LR)
- **Unstaging**: `v1` `v0` <- `v0` (LR에서 ST를 복원)
- *주의*: 만약 unstaging이 `ST -> WD`라면, Stage의 `v1`을 폴더로 다시 복사하게 되어 파일은 여전히 "staged" 상태로 남게 된다.
- **discarding (`ST -> WD`)**: 현재 Staging Area에 저장된 버전으로 작업 디렉토리를 덮어쓴다 (`git restore`). 즉, 스테이징되지 않은 모든 변경 사항을 폐기한다.