主题: version-control
-
Tags and releases: lightweight versus annotated tags and how they travel
A lightweight tag is only a name for a commit; an annotated tag is an object with tagger, date, message and optional signature, which is why git describe ignores lightweight tags by default and why releases should use annotated or signed tags; tags are not pushed with branches unless --follow-tags or --tags is used, and a published tag should never be moved.
-
Cherry-picking: when it fits and what it costs the history
git cherry-pick replays the change of a commit as a new commit with a different ID; it is the right tool for backporting a fix to a maintenance branch or salvaging one commit from an abandoned branch, but each pick creates a duplicate that merges cannot recognise, so record the origin with -x and merge instead of picking when the whole branch is wanted.
-
Recovering lost commits and branches with the reflog
The reflog records every movement of HEAD and of each branch in the local repository, so a bad reset, rebase, amend or branch deletion can be undone by finding the earlier position and putting a new branch on it; entries expire after 90 days (30 for unreachable ones) by default, and uncommitted changes were never in it.
-
Rebase or merge: integrating a branch
Merging preserves history as it happened and adds a merge commit; rebasing rewrites a branch onto a new base for a linear history. Never rebase commits that others have based work on.
-
Signing commits and tags with an SSH key or GPG
Git signs commits and tags with OpenPGP, X.509 or, since gpg.format=ssh, a plain SSH key; the signer sets gpg.format and user.signingKey, verifiers need an allowed-signers file (SSH) or a trusted key ring (GPG), and forges are checked with git verify-commit or the host's signature badge.
-
Keeping reformatting commits out of git blame: -w and ignore-revs files
git blame -w ignores whitespace when tracing lines, --ignore-rev and a committed .git-blame-ignore-revs file skip named commits such as mass reformattings so lines are attributed to the previous meaningful change, and -M/-C follow moved or copied lines; GitHub reads the same file automatically.
-
Stashing safely: messages, untracked files and stash branches
A stash is a commit stored under refs/stash whose older entries live only in that ref's reflog; give each stash a message, include untracked files deliberately, prefer apply over pop until the result is verified, and use git stash branch when the base has moved on.
-
Conventional Commits: machine-readable commit types
The Conventional Commits specification adds a typed prefix (feat, fix, and others) and breaking-change markers to commit messages so that changelogs and version bumps can be derived automatically.
-
Working in a large repository with sparse checkout and partial clone
Sparse checkout limits which directories appear in the working tree (cone mode lists directories), partial clone with --filter=blob:none delays downloading file contents until they are needed, and shallow clone truncates history; the three solve different problems and combine, but partial clone needs the promisor remote online.
-
Choosing a Git branching workflow
How long-running and topic branches combine into a workflow, and which questions decide between trunk-based, feature-branch and release-branch models.
-
Writing commit messages that explain why
A short, testable format for commit messages: a summary line under about 50 characters, a blank line, and a body that explains motivation and consequences rather than restating the diff.
-
Removing large binaries from Git history with git filter-repo
A repository stays large after a big file is deleted because every clone carries its history; shrinking means finding the offending blobs, rewriting all commits that contain them with git filter-repo in a fresh clone, force-pushing every branch and tag, and having everyone re-clone, because rewritten commits have new IDs.
-
Trunk-based development and short-lived branches
Integrating everyone's work into one shared line at least daily, keeping branches short-lived and hiding unfinished work behind flags, reduces merge conflicts and makes continuous integration real.
-
.gitattributes: line endings, diff drivers, merge drivers and export-ignore
A committed .gitattributes file settles per-path behaviour for the whole team: text=auto and eol normalise line endings, diff= assigns hunk-header patterns or textconv for binaries, merge= picks a driver such as union, binary marks files to leave alone, and export-ignore keeps paths out of git archive.
-
Submodules, subtrees or vendoring: three ways to include another repository
A submodule records a pointer (gitlink) to a commit of another repository and needs extra commands from every user; git subtree copies the other project's files and optionally its history into a subdirectory that behaves like normal files; plain vendoring copies files and records the upstream version by hand. Choose by how often the dependency changes and who must be able to clone.
-
Cleaning up a branch before review
Before asking for review, squash fix-up commits, split mixed ones and rewrite messages so that each commit is one reviewable change; git rebase -i and autosquash do the mechanical part.
-
Git LFS: pointer files, smudge filters and when not to use it
Git LFS replaces tracked large files with small text pointers (version, sha256 oid, size) and stores the contents on a separate server through clean and smudge filters; it keeps clones small but adds a second storage system with its own quotas, so tracking rarely-changing small assets or build outputs with it usually costs more than it saves.
机器可读: JSON