git命令

常用操作

  • 查看当前改动的文件
    git commit

  • 提交改动的文件
    git commit -am '任意字符串'

  • 推送自己的代码到自己的分支
    git push origin 自己创建的分支名称

  • 拉取远程仓库master的分支代码
    git pull origin master

分支相关

  • 创建分支
    git branch 分支名称
  • 创建并切换分支
    git checkout -b 分支名称
  • 查看本地分支
    git branch
  • 查看远程分支
    git branch -a
  • 删除本地分支
    git branch -D 分支名称
  • 删除远程分支
    git push origin :分支名称
  • 更新远程分支
    git fetch --prune

将远程仓库代码拉取到本地管理

  1. 在本地磁盘创建一个文件夹
    mkdir 文件夹名称
  2. 进入文件夹
    cd 文件夹名称
  3. 初始化git
    git init
  4. 添加远程仓库 (建立链接)
    git remote add origin https://gitee.com/码云昵称/项目名称(远程仓库url)
  5. 将远程仓库代码拉取到本地
    git pull origin master

杂项(不常用)

  • 解决重复输入帐号和密码
    git config --global credential.helper store
  • 更改代码颜色配置
    helper = store helper = store helper = store helper = store[color] diff = auto status = auto branch = auto[core] editor = vim[alias] st = status co = checkout ct = commit df = diff br = branch[corlor] diff = auto
  • 撤销Add操作
    git rm -r --cached [file_path]
  • 撤销提交代码仓库操作
    git blame 文件名称
  • 回滚到上一个版本
    git reset --hard HEAD~1
  • 根据log查询到的key回滚到指定版本
    git checkout 77e3873
  • 查看历史日志
    git log
  • git add 警告(warning)时输入
    git config --global core.autocrlf false
  • 打印微信端log
    tail -f app.log | grep 扫码
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。