Search code examples
xmlgithashcommitliquibase

Path to file in previous commit


Is it possible to get the path to the file from the previous commit? I have an .xml file:

<changeSet author="rozmaryn" id="040920201357" runOnChange="true" runInTransaction="true">
     <sqlFile path="storedProcedures/procedureFirst.sql"
              encoding="UTF-8"
              relativeToChangelogFile="true"/>
     <rollback>
             <sqlFile path = "<$COMMIT_HASH>/storedProcedures/procedureFirst.sql"
             encoding="UTF-8"
             relativeToChangelogFile="true"/>
     </rollback>
</changeSet>

and in the first part I have a path to sql procedure. But in <rollback> I would like to have a path to that file in a specific previous commit. It is possible (e.g. by commit hash)?


Solution

  • There is no such thing because, in your working tree, there is only one version of the project: the version corresponding to the commit HEAD is pointing to (either directly, or, more commonly, by pointing to a branch itself pointing to a commit) + the changes that have been made since that commit was made or checked out.

    The various versions of the files in your project live inside the .git directory in a compressed form. There is only one version that is uncompressed, human readable, and available for edits.

    What you can do however is to create a new file corresponding to whatever commit you are interested in.

    For instance, if you run:

    git show <hash>:<file-path> > file
    

    This will create a file called file with the content of your file of interest at your commit of interest.

    Or you can checkout your commit of interest. Your file of interest will then be in the state it was in when you made that commit:

    git checkout <hash>