Appearance
Git
CRUD
sh
# 追加改动 -> 最近 commit,不修改提交信息
git commit --amend --no-edit
# 追加改动 -> 最近 commit,修改提交信息
git commit --amend -m <commit_msg>
# 推送
git push <remote> <commit_id>:<remote_ref>
# 本地 HEAD -> 远端 test,test 已存在
git push origin HEAD:test
# 本地 abcd123 -> 远端 test,test 不存在
git push origin abcd123:refs/heads/test
# 查找历史提交内容
git log -S "console.log('test')" -p
# 只看找到的 commit
git log -S "console.log('test')" --oneline
git show <commit_id>
# 只在某文件中查找
git log -S "console.log('test')" -p -- src/utils.jsWorktree
○ 管理模式
sh
cd /work
mkdir -p ${project}
cd ${project}
git clone ${url} base
git worktree add -b ${branch} ${path} ${remote_branch}
git worktree add -b release_xxx ../release_xxx origin/release_xxx○ 常用
sh
# 查看所有 worktree
git worktree list --porcelain
# 强制删除 worktree,即使有未提交的改动
git worktree remove -f ${path}
git worktree remove -f ../release_xxx
# 清理无用的 worktree,即对应目录已被删除,但还在 worktree list,从 list 中也移除
git worktree prune
git worktree prune -n