获取自上一个标签以来的所有 git 提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12082981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:26:09  来源:igfitidea点击:

Get all git commits since last tag

gitversion-control

提问by ChocoDeveloper

When I'm going to tag a commit, I need to know what changed since the last tagged commit. Eg:

当我要标记提交时,我需要知道自上次标记提交以来发生了什么变化。例如:

a87a6sdf87a6d4 Some new feature
a87a6sdf87a6d3 Some bug fix
a87a6sdf87a6d2 Some comments added
a87a6sdf87a6d1 Some merge <- v1.4.0

In this example I would like to know about the 3 newest commits, or be able to print a log like above, that shows both commits their tags if any. And when I see there has been a new feature added, I would tag it v1.5.0.

在这个例子中,我想知道 3 个最新的提交,或者能够像上面那样打印日志,显示两个提交的标签(如果有的话)。当我看到添加了新功能时,我会将其标记为 v1.5.0。

How do you deal with this? Is this how I'm supposed to use tags? What should I write in the tag message? I always leave it blank: git tag -a v1.2.3 -m ''

你如何处理这个问题?这是我应该如何使用标签吗?我应该在标签消息中写什么?我总是把它留空:git tag -a v1.2.3 -m ''

回答by eis

git log <yourlasttag>..HEAD?

git log <yourlasttag>..HEAD?

If you want them like in your example, on the one line with commit id + message, then

如果您希望它们像在您的示例中一样,在带有 commit id + message 的一行上,然后

git log <yourlasttag>..HEAD --oneline

git log <yourlasttag>..HEAD --oneline

and in case you don't know your latest tag or want this to be dynamic, on windows you could do

如果你不知道你的最新标签或希望它是动态的,在 Windows 上你可以这样做

for /f "delims=" %a in ('git describe --tags --abbrev^=0') do @set latesttag=%a
git log %latesttag%..HEAD --oneline

and on linux / git bash / windows bash

并在 linux / git bash / windows bash

git log $(git describe --tags --abbrev=0)..HEAD --oneline

Also, if you have a case where you know a tag in history and want to print everything from that tag up to current situation, you might want to add also --decorateso it would print out any tags in between.

此外,如果您有一个案例,您知道历史中的一个标签,并且想要打印从该标签到当前情况的所有内容,您可能还想添加,--decorate以便打印出介于两者之间的任何标签。

回答by mediafreakch

If your current commit is also a tag and you want to dynamically get the changes since the previous tag, without knowing the latest tag nor previous tag name, you can do:

如果您当前的提交也是一个标签,并且您想动态获取自上一个标签以来的更改,而不知道最新的标签和前一个标签名称,您可以执行以下操作:

git log --oneline $(git describe --tags --abbrev=0 @^)..@

Note that @is short for HEAD.

请注意,它@是 的缩写HEAD