JavaWeb_瑞吉外卖_Day7-Git

Git命令

Git全局设置

获取仓库

// 本地初始化Git仓库
git init
// 克隆远程仓库
git clone [远程仓库地址]

本地仓库操作

// 查看文件状态
git status
// 将文件的修改加入暂存区
git add
// 将暂存区的文件取消暂存或者是切换到指定版本
git reset
//   - 更改版本
git reset --hard xxx
// 将暂存区的文件修改提交到版本库
git commit
// 查看日志
git log

远程仓库操作

// 查看远程仓库
git remote
git remote -v
// 添加远程仓库
git remote add [remote-name] [远程仓库地址]
// 克隆远程仓库
git clone [远程仓库地址]
// 推送至远程仓库
git push [remote-name] [branch-name]
// 从远程仓库拉取
git pull [remote-name] [branch-name]

分支操作

// 查看分支
git branch // 本地分支
git branch -r // 远程分支
git branch -a // 本地和远程分支
// 创建分支
git branch [name]
// 切换分支
git checkout [name]
// 推送至远程仓库分支
git push [remote-name] [name]
// 合并分支
git merge [name]

注意: 分支合并出错后, 手动修改合并内容, 然后git add, 接下来如果git commit报错的话, 在后面接上-i.

标签操作

// 列出已有的标签
git tag
// 创建标签
git tag [name]
// 将标签推送至远程仓库
git push [remote-name] [name]
// 新建一个分支指向某个标签
git checkout -b [branch-name] [name]

来源

黑马程序员.

经验分享 程序员 微信小程序 职场和发展