Git
Git commands.
Sites
- oh shit, git or dang it, git, when you think you messed up
- Git Tips and Tricks
git blame -w -C -C -C -L 15,26 path/to/file
, ignore rename, movements, etc.git diff --word-diff
, diff by word, e.g. tailwindgit config --global branch.sort -committerdate
, sort branches by last commitgit push --force-with-lease
, only force push if the ref is latestgit maintenance start
, cron job for prefetch and other optimizationsgit config core.fsmonitor true
on large repo, fastergit status
Notes
- Remove files that are in
.gitignore
but still in the repositorygit rm --cached path/to/file
- Copy or reset a single file from another branch/commit
git checkout <branch/commit> -- file-name.txt
- Delete a collection of branches with grep
git branch -d `git branch | grep <pattern>`
- Ignore a file without
.gitignore
- Use
.git/info/exclude
- Maybe need
git update-index --assume-unchanged path/to/file.ext
- Use
git update-index --no-assume-unchanged path/to/file.ext
to undo
- Use
Links
- Why SQLite Does Note Use Git
(HN)
- Lacks situational awareness, difficult to find successors and descendants, complex model, no historical branch names, etc.
- The Git object model
- From a blob object, to a tree object, to a commit object and how they all fit together in a Git repo
- Where do you files live in a Git repository? Julia Evans
- Tracing and finding any version of a specific file in the
.git
directory - Content addressed storage: the name of the file is the hash of the content, same content doesn't take extra space
- Tracing and finding any version of a specific file in the
- Organizing multiple git identities
(HN)
- Organize repos into separate directories
- Git config can conditionally include other git config file with
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personal
- Some miscellaneous git facts | Julia Evans
- About the staging area, internals of stashes, types of references, and merge commits diff
- Git branches: intuition and reality | Julia Evans
- Git branches are the full history of commits, not just the diff between branches
- Intuitive model: branches only contains "offshoot commits". This is helpful explaining some but not all git operations
- GQL - Git Query Language | Github @AmrDeveloper
- SQL like language to perform queries on files inside
.git
- "Tables" for
references
,commits
,diffs
,branches
, andtags
- E.g.:
SELECT DISTINCT title as tt FROM commits
- SQL like language to perform queries on files inside
- Inside
.git
| Julia Evans- A comic and explanation of what's each directory is for in
.git
- A comic and explanation of what's each directory is for in
- My favourite Git commit
(HN has some good comments
too)
- The commit
63b36f93bf75a848e2125008aa1e880c5861cf46
, plus some comments of the commit in GitHub - Explains the reason for change, error message is searchable, tells a story, reader learns something, and it builds compassion and trust
- Or maybe I would put it in the PR description or internal docs
- The commit
- Popular git config options
- A few I like:
merge.conflictstyle zdiff3
,diff.algorithm histogram
,push.autoSetupRemote true
- A few I like:
- Why Facebook doesn't use Git
- They use Mercurial. Partly technical, more so social. They were more open for collaboration and improvements
- Notes on git's error messages | Julia Evans
- Fun one, git error messages is sometimes confusing, and we are just used to being confused
- E.g. I also automatically replace 'ref' with 'branch' in error message