主题: 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.
-
Gute Commit-Nachrichten: das Warum festhalten
Eine Betreffzeile von rund 50 Zeichen im Imperativ, eine Leerzeile, dann ein Text, der Motivation, Alternativen und Folgen erklärt, statt den Diff nachzuerzählen.
-
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.
-
Reproducible asset imports: preserve identity, settings and tool versions
Build an asset workflow that can be reconstructed from a clean checkout by preserving source files, reference identity, importer configuration and the intended toolchain.
-
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.
-
让 git blame 跳过重新格式化的提交:-w 与 ignore-revs 文件
git blame -w 在追溯代码行时忽略空白差异;--ignore-rev 和提交到仓库的 .git-blame-ignore-revs 文件会跳过指定提交,例如批量重新格式化,使行归属于此前有实质意义的变更;-M/-C 跟踪移动或复制的行。GitHub 会自动读取同一文件。
-
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:机器可读的提交类型
Conventional Commits 规范为提交消息添加类型前缀(feat、fix 等)和破坏性变更标记,从而可以自动生成变更日志并确定版本升级。
-
git exit codes an agent can rely on: diff --exit-code, ls-remote --exit-code, and bisect run's 125
Most git porcelain commands only document 'non-zero on failure' without a fixed numeric table, but three commands publish an exact, citable contract: git diff/--quiet uses 1 for differences, git ls-remote --exit-code uses 2 for no matching refs, and git bisect run reserves 125 to mean 'skip this commit,' not 'bad.' A conflicted merge is signalled by state (MERGE_HEAD), not a documented number.
-
在大型仓库中使用稀疏检出和部分克隆
稀疏检出限制工作树中出现哪些目录(cone 模式使用目录列表);带 --filter=blob:none 的部分克隆将文件内容的下载推迟到实际需要时;浅克隆则截断历史。三者解决不同问题,可以组合使用,但部分克隆需要能够在线访问 promisor 远程仓库。
-
选择 Git 分支工作流
长期分支与主题分支如何组合成工作流,以及哪些问题决定应选择主干开发、功能分支还是发布分支模型。
-
编写解释原因的提交说明
一种简短、可检验的提交说明格式:大约不超过 50 个字符的摘要行、一个空行,以及解释动机和后果的正文,而不是复述差异。
-
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.
-
主干开发与短期分支
至少每天将所有人的工作集成到一条共享主线,保持分支短暂存在,并用标志隐藏未完成的工作,可以减少合并冲突,让持续集成真正落地。
-
.gitattributes:行尾、diff 驱动、merge 驱动与 export-ignore
提交到仓库的 .gitattributes 文件为整个团队统一各路径的行为:text=auto 和 eol 规范化行尾,diff= 指定差异块头部模式或用于二进制文件的 textconv,merge= 选择 union 等驱动,binary 标记应保持原样的文件,export-ignore 则将路径排除在 git archive 之外。
-
子模块、子树或直接纳入依赖副本:引入另一个仓库的三种方式
子模块记录指向另一个仓库某次提交的指针(gitlink),每位用户都需要执行额外命令;git subtree 将另一项目的文件及可选的历史复制到子目录,使用方式与普通文件相同;直接纳入依赖副本则复制文件并手动记录上游版本。应按依赖的变更频率,以及哪些人必须能够克隆仓库来选择。
-
评审前整理分支
请求评审前,将修正提交合并到原提交,拆分混杂的提交,并重写提交说明,使每个提交都成为一项可独立评审的变更;git rebase -i 和 autosquash 负责机械操作部分。
-
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