A Journal Through My Activities, Thoughts, and Notes
#git #tips

git add -A 的作用是:

1. 把 所有已追踪文件的修改和删除 加入到 staging。
2. 把 未追踪的新文件 也一并加入到 staging。
3. 把 已删除的文件 的删除操作也会加入。

简而言之:它是“所有工作区变化(新增、修改、删除)都放进暂存区”,不仅限于已经版本控制的文件。

如果你只想把已经跟踪的文件的修改加入,而忽略新文件和删除,应该用 git add -u
## 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
#git worktree

## 开新工作区

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

git config --global alias.cia 'commit -CHEAD -a --amend'

#git
修复上一次提交中的问题, 延用上一次提交的注释
git ci -a -C HEAD --amend

#git
#git diff -U10

将diff时显示的上下文行数改为10行。
 
 
Back to Top