Git 常用命令指南
在日常开发中,Git 是必不可少的版本控制工具。以下是一些最常用的命令。 基本操作 # 克隆仓库 git clone git@github.com:user/repo.git # 查看状态 git status # 添加文件到暂存区 git add filename.py git add . # 添加所有变更 # 提交 git commit -m "feat: add login feature" 分支管理 # 创建并切换分支 git checkout -b feature/new-feature # 查看分支 git branch -a # 合并分支 git checkout main git merge feature/new-feature # 删除分支 git branch -d feature/new-feature 变基 (Rebase) 变基可以让提交历史更加线性整洁。 # 变基到 main git checkout feature-branch git rebase main # 交互式变基,合并最近 3 个提交 git rebase -i HEAD~3 贮藏 (Stash) 当需要临时切换分支时,可以用 stash 保存工作进度: ...