首页 > 解决方案 > 从 git 提交生成发行说明

问题描述

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

问题是当一个分支已经开发了超过 2 周的 sprint 时,较旧的提交将不包括在内。

谁能建议我可以得到这些提交的方法?

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

标签: rubygitrake

解决方案


谁能建议我可以得到这些提交的方法?

几个选项:

  1. git tag
  2. git notes
  3. git whatchanged

git tag

阅读关于什么是 git tag 以及如何使用它的答案:什么是 git tag、如何创建标签和如何签出 git 远程标签

简而言之: git tag 允许您标记提交,稍后可以执行合并。如你所知

git pull = git fetch + git merge

因此,一旦您使用标签标记了最后一次合并,您就可以从最后一次合并中提取所有更改

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

git notes

git notes允许我们在更新提交的 SHA-1 的情况下添加要提交的内容,这意味着我们可以在不修改 SHA-1 的情况下将内容附加到提交。

在此处输入图像描述

现在一旦你有了你的笔记,你就可以找到你之前“合并”的最后一个提交,并使用上面的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

在此处输入图像描述


推荐阅读