zoukankan      html  css  js  c++  java
  • git基础实践

     

    Git 是 Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。

    git常用命令

    • 列出当前配置

      1
      git config --list
    • 列出repository配置

      1
      git config --local --list
    • 列出全局配置

      1
      git config --global --list
    • 列出系统配置

      1
      git config --system --list
    • 配置用户名

      1
      git config --global user.name "your name"
    • 配置用户邮箱

      1
      git config --global user.email "youremail@github.com"
    • 配置git命令输出为彩色

      1
      git config --global color.ui auto
    • 查看当前工作区的所有文件的状态

      1
      git status
    • 查看提交历史:

      1
      git log
    • 参数-p展开每次提交的内容差异,如-2显示最近的两次更新

      1
      git log -p -2;
    • 提交工作区所有文件到暂存区

      1
      git add .
    • 删除工作区文件并且也从暂存区删除对应文件的记录

      1
      git rm <file1> <file2>
    • 比较工作区中当前文件和暂存区之间的差异

      1
      git diff <file-name>
    • 隐藏当前变更

      1
      git stash
    • 查看当前所有的储藏

      1
      git stash list
    • 应用最新的储藏

      1
      git stash apply
    • 将暂存区中的文件提交到本地仓库

      1
      git commit -m "commit_info"
    • 将所有已经使用git管理过的文件暂存并提交,相当于执行git add和git commit

      1
      git commit -a -m "commit_info"
    • 撤销上一次提交

      1
      git commit --amend
    • 比较暂存区与上一版本的差异

      1
      git diff --cached
    • 指定文件在暂存区和本地仓库的不同

      1
      git diff <file-name> --cached
    • 列出现在所有的标签

      1
      git tag
    • 使用特定的搜索模式列出符合条件的标签

      1
      git tag -l "v1.*"
    • 创建一个含附注类型的标签,加-a参数

      1
      git tag -a v1.4 -m "my version 1.4"
    • 使用git show命令查看相应标签的版本信息

      1
      git show v2.0
    • 将标签推送到远程仓库中

      1
      2
      git push origin
      eg: git push origin v2.0
    • 将本地所有的标签全部推送到远程仓库中:

      1
      git push origin --tags
    • 创建分支

      1
      git branch <branch name>
    • 切换分支

      1
      git checkout <branch name>
    • 创建并切换到分支

      1
      git checkout -b <new branch name>
    • 删除分支

      1
      git branch -d <branch name>
    • 将当前分支与指定分支进行合并

      1
      git merge <another branch name>
    • 显示本地仓库的所有分支

      1
      git branch
    • 显示各个分支最新一次提交对象的信息

      1
      git branch -v
    • 查看哪些分支已经合并到了当前分支

      1
      git branch --merged
    • 查看哪些分支还没有合并到当前分支

      1
      git branch --no-merged
    • 把远程分支合并到当前分支

      1
      2
      3
      git merge <remote-name>/<branch name>
      eg:
      git merge origin/devel
    • 在远程分支的基础上创建新的本地分支(跟踪分支)

      1
      2
      3
      git checkout -b <branch name> <remote-name>/<branch name>
      eg:
      git checkout -b devel orgin/devel
    • 查看本地仓库关联的远程仓库,-v参数会显示远程仓库的url地址

      1
      2
      git remote
      git remote -v
    • 添加远程仓库

      1
      2
      3
      git remote add <remote-name> <url>
      eg:
      git remote add blog https://github.com/blog/blog.git
    • 从远程仓库中拉取更新

      1
      2
      git fetch <remote-name>
      git fetch origin
      • git fetch 只会讲远端数据拉到本地仓库,并不会自动合并到当前工作分支,需要人为合并,如果设置了某个分支关联到远程仓库的某个分支可以使用git pull来拉取远程分支的数据自动合并到当前分支;
    • 将本地仓库分支推送到远程仓库

      1
      2
      git push <remote name> <branch name>
      git push origin master
    • 将本地分支推送到远程仓库不同名分支

      1
      git push <remote name> <local branch>:<remote branch>
    • 删除远程分支(本地内容为空)

      1
      2
      git push <remote name> :<remote branch>
      git push origin
    • 查看远程仓库的详细信息

      1
      git remote show origin
    • 修改远程仓库在本地的简称

      1
      2
      git remote rename <old name> <new name>
      git remote rename origin ori
    • 移除远程仓库

      1
      git remote rm <remote name>
    • git clone 指定分支:

      1
      git clone -b stable-2.2 https://github.com/ansible/ansible-modules-core.git
    • git 回滚版本

      1
      2
      git reset --hard sha
      git push origin HEAD --force
    • 合并到主分支

    • git rebase和git merge的区别

    常见报错处理

    • 报错内容

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      fatal: unable to access 'https://github.com/xxxx/xxxx.github.io.git/': SSL certificate problem: self signed certificate in certificate chain
      FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
      Error: fatal: unable to access 'https://github.com/xxxx/xxxx.github.io.git/': SSL certificate problem: self signed certificate in certificate chain

      at ChildProcess.<anonymous> (H:hexo-Blog ode_moduleshexo-utillibspawn.js:37:17)
      at emitTwo (events.js:126:13)
      at ChildProcess.emit (events.js:214:7)
      at ChildProcess.cp.emit (H:hexo-Blog ode_modulescross-spawnlibenoent.js:40:29)
      at maybeClose (internal/child_process.js:925:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

      • 解决方法
        1
        git config --global http.sslVerify false
    • 报错内容

      1
      2
      Cloning into 'jplot'...
      fatal: unable to access 'https://github.com/rs/jplot.git/': Peer certificate cannot be authenticated with known CA certificates
      • 解决方法
        1
        git config --global http.sslVerify false
    • .gitigore不生效

    .gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。

    • 解决方法就是先把本地缓存删除(改变成未track状态)
      1
      2
      3
      git rm -r --cached .
      git add .
      git commit -m 'update .gitignore
    • .gitginore规则示例
      1
      2
      3
      4
      5
      6
      # 注释内容          井号开头为注释内容
      *.md # 忽略所有 .md 结尾的文件
      !readme.md # 但 readme.md 除外
      /TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括 source/TODO
      node_modules/ # 忽略 node_modules/ 目录下的所有文件
      public/*.html # 会忽略 public/index.html 但不包括 public/2019/index.html

    gitlab api操作

    1
    2
    3
    4
    5
    6
    7
    https://gitlab.local/api/v4/projects?search=roadrescue1

    https://docs.gitlab.com/ee/api/projects.html#create-project

    https://docs.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository

    https://docs.gitlab.com/ce/api/tags.html#list-project-repository-tags

    相关资料

  • 相关阅读:
    Dapper的基本使用
    Dapper
    Dapper(一) 简介和性能
    Dapper入门使用,代替你的DbSQLhelper
    Dapper-小型ORM之王(C#.NET)
    Dos.Common
    Dos.ORM(原Hxj.Data)- 目录、介绍
    读写分离
    什么是长连接,什么是短连接?长连接和短连接的区别是什么?
    HTTP的长连接和短连接
  • 原文地址:https://www.cnblogs.com/mashuqi/p/15356560.html
Copyright © 2011-2022 走看看