I want to extract a file from the last tagged version:
- if the current head is at a tagged version, then take the previous one
- else, take the last tagged version.
I am doing something like that :
#!/bin/bash
newtag=`git name-rev --tags --name-only $(git rev-parse HEAD) | sed 's|\([^\^]*\)\(\^0\)$|\1|g'`
if [[ "$newtag" == undefined ]];then
# then the current version has no tag
newtag=`git describe`
oldtag=`git tag --list | sort -V | tail -n1`
else
oldtag=`git tag --list | sort -V | tail -n2 | head -n1`
fi
# Now go grab the previous file :
git stash
git checkout $oldtag --recurse-submodules
file=`latexpand paper.tex`
git checkout $newtag --recurse-submodules
echo "$file" > oldpaper.tex
git stash pop
is there a way to do that more cleanly ? I am sure what i did to find out the right tag to go to is sub-optimal...
Moreover, getting the file is somewhat clunky right now too. The problem is that i need to ran latexexpand paper.tex
to get the file from the old verison of the repo, it is not already there. Thus, i need to checkout the older version (and stash what i currently have to do so). Is'nt there a way to ask git to run a command in the state of the oldtag
version and give me back the output more cleanly ?