一.git分支操作
- 查看分支 : git branch
创建分支: git branch <new name>
2. 查询每个分支最后一次提交 : git branch -v
$ git branch -v
master 3bbc910 代码优化
* rd ca5652f 订单退款
3. 要切换到一个已存在的分支 : git checkout rd
创建并切换分支 :git checkout -b branch_name
相当于以下两个命令:
git branch branch_name
git checkout branch_name
4. 合并某分支到当前分支:git merge 分支名
比如要将开发中的分支(deve),合并到稳定分支(master)
首先切换的master分支:git checkout master。
然后执行合并操作:git merge deve。
本地分支push到远程:git push origin master 或 git push origin deve
git push origin newbranch:newbranch //推送本地的newbranch(冒号前面的)分支到远程origin的newbranch(冒号后面的)分支(没有会自动创建)
5. 删除分支:git branch -d 分支名
二. git 回退
查看commit日志: git log
回滚、取消之前的提交: git reset --hard commit_id // commit_id 为提交记录id
提交代码: git commit a.txt -m "重新提交" // 记得不要提交不想提交的文件哦