DEV Community

WDSEGA
WDSEGA

Posted on

Git高级技巧:rebase、cherry-pick、stash等实用技巧

Git Rebase:重写提交历史

git checkout feature
git rebase main
Enter fullscreen mode Exit fullscreen mode

交互式Rebase

git rebase -i HEAD~3
# pick = 保留  |  squash = 合并  |  drop = 删除
Enter fullscreen mode Exit fullscreen mode

Git Cherry-pick:精准摘取提交

git checkout main
git cherry-pick <commit-hash>
git cherry-pick <hash1> <hash3> <hash5>
Enter fullscreen mode Exit fullscreen mode

Git Stash:临时保存工作

git stash push -m "正在开发登录功能"
git stash pop
git stash list
Enter fullscreen mode Exit fullscreen mode

Git Bisect:二分法查找Bug

git bisect start
git bisect bad HEAD
git bisect good v1.0.0
git bisect reset
Enter fullscreen mode Exit fullscreen mode

其他实用技巧

git reflog
git reset --hard <commit-hash>
git worktree add ../hotfix-dir hotfix-branch
git log -S "functionName" --all
Enter fullscreen mode Exit fullscreen mode

提交信息规范

feat(auth): 添加JWT令牌刷新功能
fix(api): 修复用户查询接口超时问题
Enter fullscreen mode Exit fullscreen mode

记住:不要对已推送的公共分支执行rebase!


📢 本文为精简版,完整版包含独家工具推荐和深度分析,请访问 WD Tech Blog 查看!

关注我的博客获取最新科技资讯、AI教程和效率工具推荐!

Top comments (0)