A Journal Through My Activities, Thoughts, and Notes
   #git
我们有时候需要快速导出一个文件,一个目录,甚至整个仓库的所有变更扔给某个AI review。这时候你就得祈祷自己的第一个提交最好是一个空提交,千万别包含什么有意义的变更。其实不用这么麻烦。git 的设计者料到了这一点,特意提供了一个黑洞hash: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 它可以充当任何git仓库的零号提交。
这么长,谁记得住?知道你会这么说,那就用下面这个别名就好。
感谢 #chatgpt
## Git 的空树(empty tree)哈希 - Git 的恒定空树对象
关键命令:
1. 得到空树哈希(恒定值)
2. 把某个提交当作从空树创建来看全部 diff(文件列表)
3. 导出完整补丁(整个提交相对于空树的 patch)
4. 另一种常用且更直接的方式(显示提交相对于“根”的 diff):
   我们有时候需要快速导出一个文件,一个目录,甚至整个仓库的所有变更扔给某个AI review。这时候你就得祈祷自己的第一个提交最好是一个空提交,千万别包含什么有意义的变更。其实不用这么麻烦。git 的设计者料到了这一点,特意提供了一个黑洞hash: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 它可以充当任何git仓库的零号提交。
这么长,谁记得住?知道你会这么说,那就用下面这个别名就好。
git config --global alias.diff0 '!git diff $(git hash-object -t tree /dev/null)'
感谢 #chatgpt
## Git 的空树(empty tree)哈希 - Git 的恒定空树对象
关键命令:
1. 得到空树哈希(恒定值)
git hash-object -t tree /dev/null
# 输出通常是:4b825dc642cb6eb9a060e54bf8d69288fbee4904
2. 把某个提交当作从空树创建来看全部 diff(文件列表)
git diff $(git hash-object -t tree /dev/null) <commit> --name-only
3. 导出完整补丁(整个提交相对于空树的 patch)
git diff $(git hash-object -t tree /dev/null) <commit> > full.patch
4. 另一种常用且更直接的方式(显示提交相对于“根”的 diff):
git diff-tree -r --root --no-commit-id <commit>
# 加上 -p 可看到 patch 内容## Git add everything except whitespace changes
In short, you can use this command:
> git diff -w -b | git apply --cached --ignore-whitespace
You can also add a #git alias like this
> git config --global alias.smartadd '!f() { git diff -w -b | git apply --cached --ignore-whitespace; }; f'
so, you can simply use 'git smartadd'
Reference
   In short, you can use this command:
> git diff -w -b | git apply --cached --ignore-whitespace
You can also add a #git alias like this
> git config --global alias.smartadd '!f() { git diff -w -b | git apply --cached --ignore-whitespace; }; f'
so, you can simply use 'git smartadd'
Reference
#git worktree 
## 开新工作区
若
这会在
## 删除不再需要的工作区
Git 会自动清理 Git 记录并删除该目录(前提是该目录是干净的,没有未提交修改)。如果有未提交修改,你需要手动处理或加
   ## 开新工作区
git worktree add ../new-dir main or other branch name
若
../new-dir 不存在,Git 会自动创建。这会在
../new-dir 下创建一个新的工作树,指向当前仓库的 main 分支,两个目录共享 .git 数据。## 删除不再需要的工作区
git worktree remove ../new-dir
Git 会自动清理 Git 记录并删除该目录(前提是该目录是干净的,没有未提交修改)。如果有未提交修改,你需要手动处理或加
--force:git worktree remove --force ../new-dir