How to Use Git with TexStudio

TexStudio is our favorite TeX editor. It works with only SVN version system. Nevertheless, using macroses one can teach it to work with Git also. To do it, one needs to create three new scripts Macros -> Add/Change in the file menu.

Get from server

%SCRIPT 
buildManager.runCommand("git pull ", editor.fileName())


Commit

%SCRIPT 
dialog = new UniversalInputDialog() 
dialog.setWindowTitle("Git commit / push") 
dialog.add("Commited by Olek P", "Comment", "comment") 
if (dialog.exec() != null) {
     comment = dialog.get("comment")
     buildManager.runCommand("git commit -a -m \"" + comment + "\"", editor.fileName())
}

Upload to server

%SCRIPT 
buildManager.runCommand("git push origin master", editor.fileName())

Windows users must change path to git. For example the last script should look like following:

%SCRIPT 
buildManager.runCommand("\"C:\\Program Files\\Git\\bin\\git.exe\" push origin master", editor.fileName())

 

UPD 21/12/2017

Show git log

%SCRIPT
buildManager.runCommand("showlog.sh", editor.fileName())

Here script showlog.sh is the following:

#!/bin/bash
FNAME='log.log' # temporary file
TEXTED='kwrite' # default text editor

git log --pretty=format:'%h : %s | Time: %cd' --graph > ${FNAME} && ${TEXTED} ${FNAME}

Compare two commits:

%SCRIPT
dialog = new UniversalInputDialog()
dialog.setWindowTitle("Choose commit:")
dialog.add("HEAD", "Recent version", "commit1")
dialog.add("HEAD^", "Elder version", "commit2")
if (dialog.exec() != null) {
commit1 = dialog.get("commit1")
commit2 = dialog.get("commit2")
buildManager.runCommand("git difftool " + commit1 + " " + commit2 + " --no-prompt ", editor.fileName())
}

 

One Comment:

  1. many thanks

Leave a Reply