Search code examples
gitshellrepositoryexportrevision

Export every revision of a single file from a Git repository?


I have a documentation .ai file versioned along my project, now I'd like to export every "snapshot" the Git repository holds for that file.

Any batch/semi-automatic solution?

I have tons of commits, have not much intention to export them one-by-one.


Solution

  • Quick, but since no one else came up with something:

    mkdir snapshots
    FILE=YourFile.ai
    i=1
    for COMMIT in $(git log --oneline $FILE | cut -f 1 -d " "); do 
      git checkout $COMMIT $FILE; 
      cp $FILE snapshots/$i-$COMMIT.ai; 
      (( i = i + 1 ))
    done
    

    Then your directory snapshots contains all versions of the file. The names consist of a number 1..n which increases with the age of each version and the respective commit together with the file extension .ai.

    P.S.: Don't forget to update FILE after that (git checkout HEAD $FILE) and don't add the folder snapshots to your repository. :)