Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

git - How do I cat revisions of a file, following it through renames?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...