git使用手册
安装git
pc.qq.com/search.html…") 直接在这里下载,官网下载太慢
git基础命令
基础流程
拉取代码 --> git clone git路径
推送代码 --> 需要多个步骤:
--> 拉取仓库代码,防止提交代码冲突 --> git pull
--> 添加需要提交的代码到暂存区 --> git add .(添加全部)
--> 提交暂存区代码 --> git commit -m [提交的备注]
--> 推送到远程仓库 --> git push
git add 其他命令
# 将某些文件提交到暂存区
git add <file1> <file2>
# 将某些目录提交到暂存区
git add <folder1> <folder2>
# 将更新之后我文件提交到暂存区
git add -u
git commit 其他命令
# 将暂存区内容提交到版本库, 进入 vi 命令界面输入提交信息
git commit
# 将某些已被跟踪的文件提交到版本库(包含工作区和版本库)
git commit [file1] [file2] [...]
# 将暂存区内容提交到版本库, 无需进入 vi 命令界面输入提交信息
git commit -m [message]
# 跳过 git add, 将所有已被跟踪的文件更改提交到版本库
git commit -am [message]
# 使用一次新的commit, 替代上一次提交
# 如果代码没有任何新变化, 则用来改写上一次commit的提交信息
git commit --amend -m [message]
git 合并操作
# 合并分支
git merge <分支名称>
git 分支操作
# 查看所有分支
git branch -a
# 查看当前分支
git branch
# 切换分支
git checkout '分支名称'
# 修改代码仓库
git remote set-url origin '仓库地址'
# 删除分支(删除前会有检查)
git branch -d '分支名称'
# 删除分支(强制删除)
git branch -D '分支名称'
#删除远程分支 git push origin :<test> 表示删除test分支
#也可以批量操作 如 git push origin :<a> :<b> :<c> 表示删除分支 a, b, c
git push <远程主机名> :<需要删除的分支名称>
git 退回提交操作
# 退回上一次提交
git reset HEAD~1
# 恢复到之前的提交
git revert <commit hash>
# 恢复到之前的版本
git checkout <commit hash>
git 标签
# 打标签
git tag '标签' '版本号'
# 查看标签列表
git tag