ruby - 从 git 提交生成发行说明

标签 ruby git rake

我在下面创建了以下 rake 任务来为每个 sprint 生成我们的发行说明。
我正在将所有提交到 master 的时间超过 2 周。

问题是当一个分支已经开发超过 2 周的冲刺时,较早的提交将不会被包括在内。

谁能建议我获取这些提交的方法?

task :new_release_note do

  puts "Creating new release note"
  puts "..."

  git_log = `git log --since="two weeks ago" --no-merges --format=%B`
  git_log.gsub!(/^$\n/, '')
  git_log.gsub!(/^/, "* ") 

  current_time = DateTime.now 
  current_date = current_time.strftime "%Y-%m-%d"
  current_date_UK = current_time.strftime "%d-%m-%Y"

  template = "__Release Notes__
  =======================
  #{current_date_UK}

  __New Features__
  ----------------

  * -


  __Improvements__
  ----------------

  * -


  __Fixes__
  ---------

  * -


  __Change Log__
  ----------------

  Detailed release notes below, listing all commit messages for this release.


  #{git_log}
  "

  out_file = File.new("./doc/release_notes/release-notes-#{current_date}.md", "w")
  out_file.puts(template)

  if File.exist?(out_file) 
    puts "New release note generated successfully at /doc/release-notes/release-notes-#{current_date}.md"
  else 
    puts "Error - file not generated."
  end 

end

最佳答案

Can anyone suggest a way I can get these commits in?

几个选项:

  1. git 标签
  2. git 笔记
  3. git whatchanged

git 标签

阅读这个关于什么是 git 标签以及如何使用它的答案:What is git tag, How to create tags & How to checkout git remote tag(s)

简而言之:git 标签允许您标记提交,稍后可以执行 merge 。众所周知

git pull = git fetch + git merge

因此,一旦您用标签标记了上次 merge ,您就可以从上次 merge 中提取所有更改

# "Merge" the last X commits based upon your previous tag
git cherry-pick <tag_name>..master

git 笔记

git notes 允许我们添加要提交的内容而无需更新提交的 SHA-1,这意味着我们可以在保留 SHA-1 的同时将内容附加到提交未修改。

enter image description here

现在一旦你有了笔记,你就可以找到你之前“merge ”的最后一次提交,并使用上面的 cherry-pick 从此时获取更改。

您可以使用 git log --grep 搜索和查找您的笔记


git whatchanged

一旦知道引用的提交是什么,您就可以使用 git whatchanged 命令查看在此期间更新的文件列表

# Print out a list of files which was updated/added between the 2 commits
git whatchanged <TAG_NAME>...HEAD

enter image description here

关于ruby - 从 git 提交生成发行说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53233810/

相关文章:

git - 安装模块的代理问题

ruby - 如何在常规任务中构建文件和目录 Rake 任务?

ruby-on-rails - Rails.cache.clear 和 rake tmp :cache:clear? 之间有什么区别

ruby-on-rails - ruby-debug-ide 是否可以安装在带有 ruby​​1.9.3 的 Windows 上?

ruby - 在 Gemfile 中将 git-repo 传递给 gem 时,需要 gem 的问题

git - 如何使用 Sublime Text 完成对提交消息的编辑?

git - 使用 GIT 升级修改后的模块

ruby - 添加反斜杠以修复 ruby​​ 字符串中的字符编码

ruby-on-rails - 你会如何用 Ruby 设计这样的 DSL?

ruby-on-rails - rake 检查是否已经在运行