[Tex/LaTex] Using TeXstudio and git to automatically commit using the current date

gittexstudio

Following up on Easy LaTeX Editor with SVN or GIT connection and auto-update, I am trying to set up a way to automatically commit my latest changes with the current date and time (e.g. -m "autosave on YYYY-MM-DD_hh:mm") to a git repository using TeXstudio (on Windows).

Using the "Automatically check in after save" feature (see image below) has the following disadvantages:

  • Cluttering of the repository (maybe to a lesser extent by saving less often); however, I am aware this is part of the functionality and can hardly be avoided
  • The function only commits the file you just saved (even worse, simply adds the current file name to the svn/git command).
    If another file was modified (which happens quite a lot if the generated PDF is part of the repository), git won't commit the changes.
    Modifying the built-in svn command to something like git -a (commit all modified files) fails since a file name is appended to the command, which gitdoesn't allow.
    To clarify, the full command executed looks like this:
    git -m "my commit message" currentfile.tex
    I have not yet found a way to not append the file name.
  • The built-in use of the % sign makes it impossible (on a Windows machine, at least) to add system variables such as %date%to the commit message

I am not dead-set on using the autosave feature; it would suffice to add a custom command to the standard compilation process.

TexStudio SVN autosave feature

Best Answer

I found a solution to this problem with the following steps:

  1. Create a batch file in the directory of your main *.tex file
  2. Open the batch file and add the following line: git commit -am "autosave %date%-%time:~0,8%". This will commit all changes made (-a switch) and set the commit message to e.g. autosave 2015-08-17-09:34:05
  3. Add a custom command in TeXstudio that executes your batch script (see image below for an example) add custom TeXstudio command
  4. Add your custom command to the list of commands for compilation add custom command to compilation
  5. After the next compilation of the document, the following message will appear in the message log: commit log message
  6. Additionally, the batch file could be modified accordingly to push the changes directly to the remote repository via git push
Related Question