简体   繁体   English

获取自上次标记以来的所有git提交

[英]Get all git commits since last tag

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. 在这个例子中,我想知道3个最新的提交,或者能够打印如上所述的日志,这表明它们都提交了它们的标签(如果有的话)。 And when I see there has been a new feature added, I would tag it v1.5.0. 当我看到添加了一个新功能时,我会将其标记为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 ''

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 如果你想要它们在你的例子中,在一行上有提交id +消息,那么

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 --decorate so it would print out any tags in between. 此外,如果您有一个案例,您知道历史记录中的标记,并希望打印从该标记到当前情况的所有内容,您可能还想添加--decorate以便打印出其间的任何标记。

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缩写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM