Git常用命令

序号命令作用示例
1 git clone 克隆版本库(下载 github 上的项目) git clone https://github.com/huanggyaaa/vue-router-simple-demo.git
2 git remote 版本库相关设置

 git remote -v  //查看远程仓库, 如果有多个显示列表

 git remote add origin https://github.com/huanggyaaa/vue-router-simple-demo.git  //添加远程仓库, origin 是别名

 git remote rm origin  // 删除 origin 这个远程仓库

 3  git add 

 提交到暂存区(被跟踪)

 git add .  // 讲所有内容保存到暂存区, 不包括删除的文件

 git add *css  // 把 css 结尾的文件添加到暂存区

 git add hello*  // 把 hello 开头的文件保存到暂存区

 git add -u  // 只保存修改过的文件到暂存区

 git add -A  // git add. 和 git add -u 功能集合

 4 git commit 提交到版本库

 git commit -m "first commit"  // 将暂存区的内容提交到版本库

 git commit -a -m "second commit"  // 将所有已跟踪的文件提交到版本库; 跳过 git add 命令

 5 git push 

 提交到远程仓库

 git push origin master  // 把 master 分支提交到 origin 远程仓库, master 分支如果不存在会被新建

 git push -u origin master  // 和上面的命令的区别是: 把 origin 设为默认远程仓库

 6 git pull

 更新远程仓库代码到本地并合并

 git pull  // 更新远程仓库的所有分支到本地并合并本地的代码, 如果远程和本地仓库某个文件同时做了修改就会报错

 7 git fetch

 更新远程仓库代码到本地

 git fetch origin master  // 从 origin 远程仓库获取 master 分支到 本地仓库的 master 分支(不会直接合并)

 git log -p master.. origin/master  // 比较本地和远程仓库的区别

 git merge origin/master  // 合并

8git branch

分支操作

 git branch  // 查看本地分支

 git branch -a  // 查看远程和本地分支

 git branch dev  // 创建 dev 分支

 git checkout dev  // 切换到 dev 分支, 工作区代码会跟着发生变化

 git branch -d dev   // 删除 dev 分支

 git push dev origin  // 把 dev 分支提交到 origin 这个远程库

 

 

 

 

撤销修改

  git log 列出提交的commit_id

  git reset --hard commit_id  // 撤销某个版本的提交, 工作区也提交, 意味着工作白费了

  git reset --soft

  

转载于:https://www.cnblogs.com/huanggy/p/10081365.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值