Reputation: 4351
Is it possible to show the history of a file - with each commit showing which tags it belongs to?
Every time we upgrade our database, one file is updated with the new schema version. Often, I'll have a database (which has the schema version in a settings table) and I'd like to look at the commits (with that version number) and see what releases (tags) they belong to.
Ideally, I'd like to be able to do this on GitHub, but I'm happy if there's something I can do on the command line.
Update
I created an Powershell version of @phd's script:
$results = $(git rev-list -5 master -- README.rst)
foreach ( $item in $results ) {
git describe $item --tags;
git show $item --no-patch
}
Upvotes: 1
Views: 780
Reputation: 95018
Command line with git log:
git log --decorate -- filename
For every commit in the log --decorate
prints tags and branches the commit belongs to.
For example, log for file README.rst
from SQLObject:
$ git log --decorate -4 -- README.rst
commit 39b3cd4
Author: Oleg Broytman <[email protected]>
Date: Sat Feb 24 19:10:59 2018 +0300
Prepare for the next release
[skip ci]
commit 0fd1c21 (tag: 3.6.0)
Author: Oleg Broytman <[email protected]>
Date: Sat Feb 24 18:50:36 2018 +0300
Release 3.6.0
commit 0684a9b (tag: 3.5.0)
Author: Oleg Broytman <[email protected]>
Date: Wed Nov 15 16:47:04 2017 +0300
SQLObject 3.5.0 released 15 Nov 2017
commit 623a580 (tag: 3.4.0)
Author: Oleg Broytman <[email protected]>
Date: Sat Aug 5 19:30:51 2017 +0300
Release 3.4.0
Upd. If the commits are not tagged git log --decorate
cannot show the nearest tag. git describe
can but it cannot list commits. So you have to list commits using git rev-list
(plumbing command behind git log
and other commands) and git describe
:
$ git rev-list -5 master -- README.rst | xargs git describe
3.6.0-1-g39b3cd4
3.6.0
3.5.0
3.4.0
3.3.0-2-g3d2bf5a
But then you loose commit's hashes and content. You need to write a script to show all information at once. Something like that:
for H in $(git rev-list -5 master -- README.rst); do
git describe $H; git show $H
done
Upvotes: 3