How do I cat revisions of a file, following it thr

2019-08-16 10:22发布

问题:

I can do this just fine:

git log --format=%h -- filename | while read f; do git show $f:filename; done

However, if I try to add --follow to the git log call, the file moves through directories and changes names, so the git show call fails on the path change. I've tried inserting various things to grab the full path (fullname=`ls-tree --name-only $f -- filename`, etc.) and passing it on to git show, but nothing's working, and I'm not finding much with google and SO searches. I feel like I'm missing something obvious, like a git log --format trick.

I'd also accept just getting all the full path names the file has ever been, and a way to get the full history of no-longer existing paths. Then I could take this in stages, though of course I'd prefer the all-at-once approach.

回答1:

I managed to pull out the data I need with this:

`git log --follow --format='%h' --name-only -- filename | vim -`

Information came in like this to Vim:

21acc7c

work/oldname
dea4a67

work/filename
103b0ee

work/subfolder/filename
387b384

work/filename
741bbc7

filename

etc...

I did :g/filename/norm kkJJ to join them into this:

21acc7c work/oldname
dea4a67 work/filename
103b0ee work/subfolder/filename
387b384 work/filename
741bbc7 filename

This let me regex things into what I needed, though I had to jump through some hoops to keep things sorted, as git only stores down to the second, and rebases tend to create many commits at exactly the same time. The parenting keeps the order, but it meant that I had to deal with ordering in the looping, and not based on anything like git show or git log info.



标签: git history