Sum's blog Sum's blog
  • 知识

    • Markdown语法
    • ASCII (opens new window)
    • 缩略语
  • 语言篇

    • C
    • C++
    • C#
    • Python
    • Verilog
  • 必备篇

    • Git
    • Linux
    • 环境搭建
  • 工作专项

    • WLAN从入门到精通 Wi-Fi 6
    • 企业WLAN架构与技术
  • Games

    • CSGO
  • Evan's

    • OtherBlog
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 摘抄
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Sum

有苦吗我有时间
  • 知识

    • Markdown语法
    • ASCII (opens new window)
    • 缩略语
  • 语言篇

    • C
    • C++
    • C#
    • Python
    • Verilog
  • 必备篇

    • Git
    • Linux
    • 环境搭建
  • 工作专项

    • WLAN从入门到精通 Wi-Fi 6
    • 企业WLAN架构与技术
  • Games

    • CSGO
  • Evan's

    • OtherBlog
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 摘抄
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 语言篇

  • 必备篇

    • Git笔记
      • Linux

      • 环境搭建

      • 编程更好地可视化
    • 工作专项篇

    • games

    • 笔记
    • 必备篇
    wangzhe
    2021-11-16
    目录

    Git笔记

    | git官方Ebook (opens new window) | 腾讯云Git教程 (opens new window) | 廖雪峰Git入门教程 (opens new window) |

    | Git动画理解(有空复习) (opens new window) |

    # 1.基本语句:

    ssh-keygen -t rsa -C "[111@qq.com](mailto:111@qq.com)" (git邮箱) # 生成私钥
    
    git config --global user.name "填写自己的用户名"               # 配置个人用户名
    git config --global user.email 填写自己的邮箱号                   #电子邮件地址
    git config --list                                 #查看配置信息
    
    git init    # 初始化一个git项目
    
    git status   # 查看当前文件的git状态
    
    git add 文件名称   # 告诉git,管理某个文件(追踪某个文件)
    
    git add .(点)    # 添加当前目录下的所有文件
    
    git commit -m "注释"   # 提交版本
    
    git branch # 查看当前的分支
    
    git branch checkout # 切换分支
    
    git log --pretty=oneline  # 查看之前的commit,缩短到一行
    
    //查询当前远程的版本
    $ git remote -v
    //获取最新代码到本地(本地当前分支为[branch],获取的远端的分支为[origin/branch])
    $ git fetch origin master  [示例1:获取远端的origin/master分支]
    $ git fetch origin dev [示例2:获取远端的origin/dev分支]
    //查看版本差异
    $ git log -p master..origin/master [示例1:查看本地master与远端origin/master的版本差异]
    $ git log -p dev..origin/dev   [示例2:查看本地dev与远端origin/dev的版本差异]
    //合并最新代码到本地分支
    $ git merge origin/master  [示例1:合并远端分支origin/master到当前分支]
    $ git merge origin/dev [示例2:合并远端分支origin/dev到当前分支]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33

    # 2. Commit message

    参考这里:http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

    https://www.cnblogs.com/deng-cc/p/6322122.html

    Git 每次提交代码,都要写 Commit message(提交说明),否则就不允许提交。

    $ git commit -m "hello world"
    
    1

    上面代码的-m参数,就是用来指定 commit mesage 的。

    如果一行不够,可以只执行git commit,就会跳出文本编辑器,让你写多行。

    $ git commit
    
    1

    一般来说,commit message 应该清晰明了,说明本次提交的目的。

    # Commit message 的格式

    每次提交,Commit message 都包括三个部分:Header,Body 和 Footer。

    <type>(<scope>): <subject>
    // 空一行
    <body>
    // 空一行
    <footer>
    
    1
    2
    3
    4
    5

    其中,Header 是必需的,Body 和 Footer 可以省略。

    不管是哪一个部分,任何一行都不得超过72个字符(或100个字符)。这是为了避免自动换行影响美观。

    e.g.

    feat: init LearnGit.git
    
    I got a wrong-style git commit, so I init a .git for learning
    how to write a git commit message in right way.
    
    And the last line just write here for a simple test,
    it's useless acturally.
    
    1
    2
    3
    4
    5
    6
    7
    # 1 Header

    Header部分只有一行,包括三个字段:type(必需)、scope(可选)和subject(必需)。

    (1)type

    type用于说明 commit 的类别,只允许使用下面7个标识。

    • feat:新功能(feature)
    • fix:修补bug
    • docs:文档(documentation)
    • style: 格式(不影响代码运行的变动)
    • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
    • test:增加测试
    • chore:构建过程或辅助工具的变动

    如果type为feat和fix,则该 commit 将肯定出现在 Change log 之中。其他情况(docs、chore、style、refactor、test)由你决定,要不要放入 Change log,建议是不要。

    (2)scope

    scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。

    (3)subject

    subject是 commit 目的的简短描述,不超过50个字符。

    • 以动词开头,使用第一人称现在时,比如change,而不是changed或changes
    • 第一个字母小写
    • 结尾不加句号(.)
    # 2 Body

    Body 部分是对本次 commit 的详细描述,可以分成多行。下面是一个范例。

    More detailed explanatory text, if necessary.  Wrap it to 
    about 72 characters or so. 
    
    Further paragraphs come after blank lines.
    
    - Bullet points are okay, too
    - Use a hanging indent
    
    1
    2
    3
    4
    5
    6
    7

    有两个注意点。

    (1)使用第一人称现在时,比如使用change而不是changed或changes。

    (2)应该说明代码变动的动机,以及与以前行为的对比。

    编辑 (opens new window)
    #Git
    上次更新: 2022/06/20, 15:39:19
    Verilog笔记
    Linux历史拓展

    ← Verilog笔记 Linux历史拓展→

    最近更新
    01
    编程更好地可视化
    07-04
    02
    C语言编程规范
    07-01
    03
    摘抄
    05-29
    更多文章>
    Theme by Vdoing | Copyright © 2019-2022 Sum | MIT License | 鲁ICP备20003168号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式