Git常用命令

命令名称 作用
git config —global user.name 用户名 设置用户签名
git config —global user.email 邮箱 设置用户签名
git init 初始化本地库
git status 查看本地库状态
git add 文件名 / . 将文件添加到暂存区
git commit -m “日志信息” [文件名] 提交到本地库
git reflog 查看版本信息
git log 查看版本详细信息
git reset —hard 版本号 切换本本,不是切换分支
git push [-u 远程仓库名称 分支名] 代码提交

Git分支

命令名称 作用
git branch 分支名 创建分支
git branch -v 查看所有分支和当前所在分支
git branch -d 分支名 删除分子
git branch -m 老分支名 新分支名 修改分支名字
git checkout 分支名 切换分支
git merge 分支名 把指定的分支合并到当前分支上

Git合并冲突解决

合并冲突文件内容展现形式

1
2
3
4
5
<<<<<<< HEAD
当前分支内容
=======
其他分支内容
>>>>>>> abc

当前处于master分支进行合并

1
2
3
4
5
<<<<<<< HEAD
master分支
=======
abc分支
>>>>>>> abc

保留当前分支内容

1
master分支

保留其他分支内容

1
abc分支

Git远程仓库使用

命令名称 作用
git remote -v 显示所有远程仓库
git remote add [远程仓库名称] [url] 添加远程仓库信息
git push [-u 远程仓库名] [远程仓库分支] 提交远程库
git remote rm name 删除远程仓库
git remote rename old_name new_name 修改仓库名

密钥生成

输入下面命令,然后一直按回车

1
ssh-keygen -t rsa -C 1903078434@qq.com