我在下面创建了以下 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?
几个选项:
git 标签
git 笔记
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 的同时将内容附加到提交未修改。
现在一旦你有了笔记,你就可以找到你之前“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
关于ruby - 从 git 提交生成发行说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53233810/