【iTools】代码版本控制 git 流

工具 tools

常用指令

# clone repo
git clone url_to_repo
# pull from server
git pull
# add cotent and commit with message
git commit -am "message"
# push to server
git push

.gitignore 文件

  • 使用 VS,PyCharm 等IDE时候, 使用这些IDE自带的Git 初始化, 这样创建的 .gitignore 文件最恰当.
  • 没有IDE时候,从 Github模板找, 如 Python.gitignore,
  • 再加上自己的经验积累编写。个人积累的一些 模板
  • 基本语法如下
# 忽略 .a 文件
*.a

# 但否定忽略 lib.a, 尽管已经在前面忽略了 .a 文件
!lib.a

# 仅在当前目录下忽略 TODO 文件, 但不包括子目录下的 subdir/TODO
/TODO

# 忽略 build/ 文件夹下的所有文件
build/

# 忽略 doc/notes.txt, 不包括 doc/server/arch.txt
doc/*.txt

# 忽略所有的 .pdf 文件 在 doc/directory/ 下的
doc/**/*.pdf

Git 使用风格指南

主要是参考自Git Style Guide和自己的使用习惯体会.

Branches

  • 项目初始化为 master, devfeature 三条主线.
  • 在主线之上, 再开支线, 命名一定要简洁,清晰. Choose short and descriptive names, 单词之间使用 - 连接.
# good
$ git checkout -b oauth-migration

# bad - too vague
$ git checkout -b login_fix

Commits

  • 每个提交应当只包含一个简单的逻辑改动,不要在一个提交里包含多个逻辑改动。比如,如果一个补丁修复了一个 Bug,又优化了一个特性的性能,就将其拆分。
  • 不要将一个逻辑改动拆分提交。例如一个功能的实现及其对应的测试应当一并提交。
  • 尽早、尽快提交。出问题时,短小、完整的提交更容易发现并修正。
  • 提交应当依逻辑排序。例如,如果 X 提交依赖于 Y,那么 Y 提交应该在 X 前面。

Messages

  • 分为两部分, header 和 body
  • header 部分动词开头起始语气, 结果没有. 号. 核心表意完整
# good - imperative present tense, capitalized, fewer than 50 characters
Mark huge records as obsolete when clearing hinting faults

# bad
fixed ActiveModel::Errors deprecation messages failing when AR was used outside of Rails.
  • body 部分, 正文部分. 要时刻考虑若干时日后, 自己回头看或者他人来接手自己的代码的时候, 希望获取哪些信息. 一般, 解释为什么需要改动, 如何解决了这个 issue 以及它有什么副作用。最好提供相关资源的链接,例如 bug tracker 的 issue 编号.
Short (50 chars or fewer) summary of changes

More detailed explanatory text, if necessary. Wrap it to
72 characters. In some contexts, the first
line is treated as the subject of an email and the rest of
the text as the body.  The blank line separating the
summary from the body is critical (unless you omit the body
entirely); tools like rebase can get confused if you run
the two together.

Further paragraphs come after blank lines.

- Bullet points are okay, too

- Use a hyphen or an asterisk for the bullet,
  followed by a single space, with blank lines in
  between

Source http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

Tips

  • 保持统一, 这涉及到从工作流到你的提交信息,分支名还有标签。 在整个 Repository 中保持统一的命名风格有助于辨认工作进度。
  • push 前测试, 不要提交未完成的工作。
  • 在版本或者其他重要的时间点, 多做tag。

Ref

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值