Home > Back-end >  What's a convenient way of showing the latest version of a deleted file?
What's a convenient way of showing the latest version of a deleted file?

Time:05-31

I can do:

git-showlatest(){ git show $(git log -p -- "$1" |grep commit|head -n1|cut -d\  -f2):"$1"; }

as a bash function.

Is there a better way?

CodePudding user response:

First of all, you're missing a caret (^):

git-showlatest() 
{ 
    git show "$(git log -p -- "$1" |grep commit|head -n1|cut -d\  -f2)^:$1"
}

You need the caret because in the revision in question, the file doesn't exist - because it was deleted, so you want the version that existed in the revision before that.

But as @zedfoxus said, you don't need to do this parsing (and you can also use xargs):

git-showlatest() 
{ 
    git log -n 1 --pretty='format:%H' -- "$@" \
        | xargs -I '{}' git show "{}^:$1"
}
  •  Tags:  
  • git
  • Related