From 1b997955d4baf2f22890b2deda74480d5654e487 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 1 May 2024 15:27:42 +0200 Subject: git: move to development --- src/SUMMARY.md | 2 +- src/development/README.md | 1 + src/development/git.md | 233 ++++++++++++++++++++++++++++++++++++++++++++++ src/tools/README.md | 1 - src/tools/git.md | 233 ---------------------------------------------- 5 files changed, 235 insertions(+), 235 deletions(-) create mode 100644 src/development/git.md delete mode 100644 src/tools/git.md (limited to 'src') diff --git a/src/SUMMARY.md b/src/SUMMARY.md index e578781..e770c09 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -15,7 +15,6 @@ - [Tools](./tools/README.md) - [tmux](./tools/tmux.md) - - [git](./tools/git.md) - [emacs](./tools/emacs.md) - [gpg](./tools/gpg.md) - [radare2](./tools/radare2.md) @@ -57,6 +56,7 @@ - [c++](./development/c++.md) - [glibc](./development/glibc.md) - [gcc](./development/gcc.md) + - [git](./development/git.md) - [cmake](./development/cmake.md) - [make](./development/make.md) - [ld.so](./development/ld.so.md) diff --git a/src/development/README.md b/src/development/README.md index af18a02..3363308 100644 --- a/src/development/README.md +++ b/src/development/README.md @@ -4,6 +4,7 @@ - [c++](./c++.md) - [glibc](./glibc.md) - [gcc](./gcc.md) +- [git](./git.md) - [cmake](./cmake.md) - [make](./make.md) - [ld.so](./ld.so.md) diff --git a/src/development/git.md b/src/development/git.md new file mode 100644 index 0000000..34c5baa --- /dev/null +++ b/src/development/git.md @@ -0,0 +1,233 @@ +# git(1) + +## Working areas +```text ++-------------------+ --- stash -----> +-------+ +| working directory | | stash | // Shelving area. ++-------------------+ <-- stash pop -- +-------+ + | ^ + add | + | reset + v | ++-------------------+ +| staging area | ++-------------------+ + | + commit + | + v ++-------------------+ +| local repository | ++-------------------+ + | ^ + push | + | fetch / + | pull + v | ++-------------------+ +| remote repository | ++-------------------+ +``` + +## Config +```markdown + git config --list --show-origin ..... list currently set configs and where + they are coming from + git --edit [--global] ............... open config in editor (local or global) +``` + +## Clean +```markdown + git clean -X ......... remove only ignored files (-n for dry run) + git clean -f -d -x ... remove untracked & ignored files / folders + git clean -e ... exclude pattern from deletion +``` + +## Staging +```markdown + git add -p [] ............ partial staging (interactive) +``` + +## Remote +```markdown + git remote -v .................. list remotes verbose (with URLs) + git remote show [-n] .. list info for (like remote HEAD, + remote branches, tracking mapping) +``` + +## Branching +```markdown + git branch [-a] ................ list available branches; -a to include + remote branches + git branch -vv ................. list branch & annotate with head sha1 & + remote tracking branch + git branch ............. create local branch with name + git branch -d .......... delete local branch with name + git checkout ........... switch to branch with name + git checkout --track .. start to locally track a remote branch + git branch --unset-upstream .... unset remote tracking branch + + # Remote + + git push -u origin ........ push local branch to origin (or other + remote), and setup as tracking + branch + git push origin --delete .. delete branch from origin (or + other remote) +``` + +## Update local from remote +```markdown + git fetch --prune .................. update all remote references and + remove delete non-existing ones + (does not merge into local tracking branch) + git pull [--rebase] ................ fetch remote references and merge into + local tracking branch (fast-forward by default). + Optionally rebase local tracking branch + on-top of remote branch (in case local + branch has additional commits compared to remote branch). +``` + +## Tags +```markdown + git tag -a -m "descr" ........ creates an annotated tag (full object + containing tagger, date, ...) + git tag -l ........................... list available tags + git checkout tag/ ............. checkout specific tag + git checkout tag/ -b .. checkout specific tag in a new branch + + # Remote + + git push origin --tags .... push local tags to origin (or other remote) +``` + +## Merging +```markdown + git merge [opt] .... integrate changes from since + opt: current branch and diverged + --squash ................ merge all commits into a single one + --no-commit ............. dont generate commit if the merge succeeds + + git merge-base + get the common ancestor, since both commits diverged + + git rebase -i .... interactively rebase on , also supports actions + like squashing, editing, rewording, etc of commits + + git cherry-pick .... apply commit on current branch +``` + +## Worktree +Worktrees allow to maintain multiple working trees in the filesystem linked to +the same repository (shared .git folder). +```markdown + git worktree add .............. create a tree at with a new branch + checked out (bname is basename of ) + git worktree add ...... create a tree at from existing + git worktree list .................... list existing work trees + git worktree remove ........... remove work tree + git worktree prune ................... remove stale bookkeeping files +``` + +## Log & Commit History +```markdown + git log --oneline ......... shows log in single line per commit -> alias for + '--pretty=oneline --abbrev-commit' + git log --graph ........... text based graph of commit history + git log --decorate ........ decorate log with REFs + + git log -p ......... show commit history + diffs for + git log --oneline .. show commit history for in compact format +``` + +## Diff & Commit Info +```markdown + git diff .. [] .... show changes between two arbitrary + commits. If one is omitted + it is if HEAD is specified. + git diff --name-only .. . show names of files changed + git diff -U$(wc -l ) ....... shows complete file with diffs + instead of usual diff snippets + git diff --staged ....................... show diffs of staged files + + git show --stat ................ show files changed by + git show [] .............. show diffs for + + git show : ................ show at +``` + +## Patching +```markdown + git format-patch / + opt: + -N ................... use [PATCH] instead [PATCH n/m] in subject when + generating patch description (for patches spanning + multiple commits) + --start-number ... start output file generation with as start + number instead '1' + since spcifier: + -3 .................. e.g: create a patch from last three commits + ....... create patch with commits starting after + + git am ......... apply patch and create a commit for it + + git apply --stat ... see which files the patch would change + git apply --check .. see if the patch can be applied cleanly + git apply [-3] ..... apply the patch locally without creating a commit, + if the patch does not cleanly apply -3 allows for + a 3-way merge + + # eg: generate patches for each commit from initial commit on + git format-patch -N $(git rev-list --max-parents=0 HEAD) + + # generate single patch file from a certain commit/ref + git format-patch --stdout > my-patch.patch +``` + +## Resetting +```markdown + git reset [opt] + opt: + --mixed .................... resets index, but not working tree + --hard ..................... matches the working tree and index to that + of the tree being switched to any changes to + tracked files in the working tree since + are lost + git reset HEAD .......... remove file from staging + git reset --soft HEAD~1 ........ delete most recent commit but keep work + git reset --hard HEAD~1 ........ delete most recent commit and delete work +``` + +## Submodules +```markdown + git submodule add [] .......... add new submodule to current project + git clone --recursive ............... clone project and recursively all + submodules (same as using + 'git submodule update --init + --recursive' after clone) + git submodule update --init --recursive ... checkout submodules recursively + using the commit listed in the + super-project (in detached HEAD) + git submodule update --remote .... fetch & merge remote changes for + , this will pull + origin/HEAD or a branch specified + for the submodule + git diff --submodule ...................... show commits that are part of the + submodule diff +``` + +## Inspection +```markdown + git ls-tree [-r] .... show git tree for , -r to recursively ls sub-trees + git show ............ show + git cat-file -p ..... print content of +``` + +## Revision Specifier +```markdown + HEAD ........ last commit + HEAD~1 ...... last commit-1 + HEAD~N ...... last commit-N (linear backwards when in tree structure, check + difference between HEAD^ and HEAD~) + git rev-list --max-parents=0 HEAD ........... first commit +``` diff --git a/src/tools/README.md b/src/tools/README.md index 5656233..d2a45e9 100644 --- a/src/tools/README.md +++ b/src/tools/README.md @@ -1,7 +1,6 @@ # Tools - [tmux](./tmux.md) -- [git](./git.md) - [emacs](./emacs.md) - [gpg](./gpg.md) - [radare2](./radare2.md) diff --git a/src/tools/git.md b/src/tools/git.md deleted file mode 100644 index 34c5baa..0000000 --- a/src/tools/git.md +++ /dev/null @@ -1,233 +0,0 @@ -# git(1) - -## Working areas -```text -+-------------------+ --- stash -----> +-------+ -| working directory | | stash | // Shelving area. -+-------------------+ <-- stash pop -- +-------+ - | ^ - add | - | reset - v | -+-------------------+ -| staging area | -+-------------------+ - | - commit - | - v -+-------------------+ -| local repository | -+-------------------+ - | ^ - push | - | fetch / - | pull - v | -+-------------------+ -| remote repository | -+-------------------+ -``` - -## Config -```markdown - git config --list --show-origin ..... list currently set configs and where - they are coming from - git --edit [--global] ............... open config in editor (local or global) -``` - -## Clean -```markdown - git clean -X ......... remove only ignored files (-n for dry run) - git clean -f -d -x ... remove untracked & ignored files / folders - git clean -e ... exclude pattern from deletion -``` - -## Staging -```markdown - git add -p [] ............ partial staging (interactive) -``` - -## Remote -```markdown - git remote -v .................. list remotes verbose (with URLs) - git remote show [-n] .. list info for (like remote HEAD, - remote branches, tracking mapping) -``` - -## Branching -```markdown - git branch [-a] ................ list available branches; -a to include - remote branches - git branch -vv ................. list branch & annotate with head sha1 & - remote tracking branch - git branch ............. create local branch with name - git branch -d .......... delete local branch with name - git checkout ........... switch to branch with name - git checkout --track .. start to locally track a remote branch - git branch --unset-upstream .... unset remote tracking branch - - # Remote - - git push -u origin ........ push local branch to origin (or other - remote), and setup as tracking - branch - git push origin --delete .. delete branch from origin (or - other remote) -``` - -## Update local from remote -```markdown - git fetch --prune .................. update all remote references and - remove delete non-existing ones - (does not merge into local tracking branch) - git pull [--rebase] ................ fetch remote references and merge into - local tracking branch (fast-forward by default). - Optionally rebase local tracking branch - on-top of remote branch (in case local - branch has additional commits compared to remote branch). -``` - -## Tags -```markdown - git tag -a -m "descr" ........ creates an annotated tag (full object - containing tagger, date, ...) - git tag -l ........................... list available tags - git checkout tag/ ............. checkout specific tag - git checkout tag/ -b .. checkout specific tag in a new branch - - # Remote - - git push origin --tags .... push local tags to origin (or other remote) -``` - -## Merging -```markdown - git merge [opt] .... integrate changes from since - opt: current branch and diverged - --squash ................ merge all commits into a single one - --no-commit ............. dont generate commit if the merge succeeds - - git merge-base - get the common ancestor, since both commits diverged - - git rebase -i .... interactively rebase on , also supports actions - like squashing, editing, rewording, etc of commits - - git cherry-pick .... apply commit on current branch -``` - -## Worktree -Worktrees allow to maintain multiple working trees in the filesystem linked to -the same repository (shared .git folder). -```markdown - git worktree add .............. create a tree at with a new branch - checked out (bname is basename of ) - git worktree add ...... create a tree at from existing - git worktree list .................... list existing work trees - git worktree remove ........... remove work tree - git worktree prune ................... remove stale bookkeeping files -``` - -## Log & Commit History -```markdown - git log --oneline ......... shows log in single line per commit -> alias for - '--pretty=oneline --abbrev-commit' - git log --graph ........... text based graph of commit history - git log --decorate ........ decorate log with REFs - - git log -p ......... show commit history + diffs for - git log --oneline .. show commit history for in compact format -``` - -## Diff & Commit Info -```markdown - git diff .. [] .... show changes between two arbitrary - commits. If one is omitted - it is if HEAD is specified. - git diff --name-only .. . show names of files changed - git diff -U$(wc -l ) ....... shows complete file with diffs - instead of usual diff snippets - git diff --staged ....................... show diffs of staged files - - git show --stat ................ show files changed by - git show [] .............. show diffs for - - git show : ................ show at -``` - -## Patching -```markdown - git format-patch / - opt: - -N ................... use [PATCH] instead [PATCH n/m] in subject when - generating patch description (for patches spanning - multiple commits) - --start-number ... start output file generation with as start - number instead '1' - since spcifier: - -3 .................. e.g: create a patch from last three commits - ....... create patch with commits starting after - - git am ......... apply patch and create a commit for it - - git apply --stat ... see which files the patch would change - git apply --check .. see if the patch can be applied cleanly - git apply [-3] ..... apply the patch locally without creating a commit, - if the patch does not cleanly apply -3 allows for - a 3-way merge - - # eg: generate patches for each commit from initial commit on - git format-patch -N $(git rev-list --max-parents=0 HEAD) - - # generate single patch file from a certain commit/ref - git format-patch --stdout > my-patch.patch -``` - -## Resetting -```markdown - git reset [opt] - opt: - --mixed .................... resets index, but not working tree - --hard ..................... matches the working tree and index to that - of the tree being switched to any changes to - tracked files in the working tree since - are lost - git reset HEAD .......... remove file from staging - git reset --soft HEAD~1 ........ delete most recent commit but keep work - git reset --hard HEAD~1 ........ delete most recent commit and delete work -``` - -## Submodules -```markdown - git submodule add [] .......... add new submodule to current project - git clone --recursive ............... clone project and recursively all - submodules (same as using - 'git submodule update --init - --recursive' after clone) - git submodule update --init --recursive ... checkout submodules recursively - using the commit listed in the - super-project (in detached HEAD) - git submodule update --remote .... fetch & merge remote changes for - , this will pull - origin/HEAD or a branch specified - for the submodule - git diff --submodule ...................... show commits that are part of the - submodule diff -``` - -## Inspection -```markdown - git ls-tree [-r] .... show git tree for , -r to recursively ls sub-trees - git show ............ show - git cat-file -p ..... print content of -``` - -## Revision Specifier -```markdown - HEAD ........ last commit - HEAD~1 ...... last commit-1 - HEAD~N ...... last commit-N (linear backwards when in tree structure, check - difference between HEAD^ and HEAD~) - git rev-list --max-parents=0 HEAD ........... first commit -``` -- cgit v1.2.3