Git 常用命令

记录一些常用的 Git 命令

常用
  • 将项目从远程克隆到本地
    git clone git地址 本地路径
  • 提交本地代码到远程
    git add --all  添加本地修改
    git commit -m "message"     标记一下本次提交,利于回溯
    git pull origin branchname  获取远程代码
    git push origin branchname  将代码提交到远程
  • 查看文件的状态
    git status  查看没有被add进git版本库的文件
其他
    git stash  如果错误的pull了代码,可以使用这个命令返回
分支
  • 查看本地仓库所有分支,当前所在的分支
    git branch
  • 查看远程分支
    git branch  -r  
  • 查看本地和远程的所有分支
    git branch  -a  
  • 切换分支
    git checkout branchname 
  • 删除分支
    git branch -d  branchname
  • 删除远程的分支
    git push origin --delete branchname
  • 合并分支,将指定分支合并到当前分支
    git merge branchname
  • 给本地的分支重命名
    git branch -m oldname newname
  • 新建分支,如果有不会新建
    git checkout -b branchname
tag
  • 给分支打tag
    git tag -a v0.0.1 -m "msg"
  • 查看 tag
    git tag
  • 查看v0.0.1 tag 的详细信息
    git show v0.0.1
  • 切换到 tag 版本
    git checkout -b newbranch tag
  • 将本地所有tag上传
    git push --tags
  • 上传指定版本的 tag
    git push origin v0.0.1
  • 删除本地分支
    git tag -d v0.0.1
  • 删除远程分支
    git push origin :refs/tags/v0.0.1
回溯版本
  • 查看commit记录
    git log 
  • 回滚到 commit 的版本号
    git reset —hard 版本号 
git rebase
  • 执行rebase
    git rebase origin 
  • 合并后,继续工作
    git rebase --continue
  • 退出rebase
    git rebase - -abort 
修改本地仓库git指向
步骤:
  • 删除仓库的远程地址
    git remote rm origin
  • 添加新地址
    git remote add origin 新地址  
  • 查看远程仓库地址
    git  remote -v   
把本地的项目上传到github
参考:地址
步骤:
  • 添加账户名
    git config --global user.name "github账户名"  
  • 添加 email 地址
    git config --global user.email 注册github的邮箱地址  
  • 初始化 Git 仓库
    git init   
  • 添加所有文件到 Git 仓库
    git add --all   
  • commit 此次提交
    git commit -m "message"   
  • 添加远程指向
    git remote add origin https://github.com:xxx/xxx.git   
  • push 到远程
    git push -u origin master
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值