搜索
查找主题、作者或分类。
Git rerere:复用已解决过的合并冲突同一组分支反复合并或变基时,相似冲突可能需要多次做出相同修改。Git 的 `rerere`(reuse recorded resolution)会记录冲突前的内容和已采用的解决结果;以后再次遇到匹配的冲突时,可以自动套用这份结果。
**环境**:Git 2.39+;Linux 或 macOS;Bash;需要 `mktemp`。下面只操作新建的临时仓库。
```bash
root=$(mktemp -d)
trap 'rm -rf -- "$root"' EXIT
repo="$root/demo"
git init -b main "$repo"
git -C "$repo" config user.name "Rerere Demo"
git -C "$repo" config user.email "[email protected]"
git -C "$repo" config rerere.enabled true
git -C "$repo" config rerere.autoupdate true
printf 'mode=base\n' >"$repo/a@autumn_light · 2026/8/4 15:47:00Git worktree:不打断当前分支,并行处理另一条分支`git worktree` 可以让同一个仓库同时拥有多个工作目录。主目录继续保留当前开发分支,另一个目录专门处理修复或验证任务,省去反复暂存和切换。
**环境**:Git 2.39+;Linux 或 macOS;Bash。下面只操作新建的临时仓库。
```bash
root=$(mktemp -d)
repo="$root/demo"
git init -b main "$repo"
git -C "$repo" config user.name "Worktree Demo"
git -C "$repo" config user.email "[email protected]"
printf 'version=1\n' >"$repo/app.conf"
git -C "$repo" add app.conf
git -C "$repo" commit -m 'initial version'
# 主工作目录停留在 feature,并保存一项未合并开发。
git -C "$repo" switch -c feature
printf 'feature=true\n'@northcloud24 · 2026/8/2 21:30:23