I have a tex document which automatically retrieves the current commit hash and branch name from the respectives files and puts that at the top of my document as a type of version control when reading the actual doc. The problem with that is that when I save the file, I get the previous commit because obviously when I then use git commit
the commit hash changes. I'm using TeXstudio to edit my file. The problem is that after commiting I can't edit the file anymore or rather the older version is used even if I edit my document after the commit.
Asked
Active
Viewed 32 times
0

Yakuwari
- 39
- 5
-
1You can't easily make a commit which references itself. Many languages allow you to fetch the commit information dynamically e.g. by running `git describe` at build time, which of course isn't exactly what you asked for, but probably the easiest feasible approximation. – tripleee Aug 08 '21 at 16:23
-
1Maybe the https://www.ctan.org/pkg/gitinfo2 package could help? You don't need to edit your document after the commit, just compile it again (which could even be automated) – samcarter_is_at_topanswers.xyz Aug 08 '21 at 16:26
-
@samcarter_is_at_topanswers.xyz By "editing" I meant compiling it again. But if I do that after the commit, it still uses the previous version from before recompiling. – Yakuwari Aug 08 '21 at 18:10
-
I assume you are committing the produced file (eg. pdf) to the repository? If that case it's basically impossible to get the hash of the commit that would be created after the output files are produced. You would have to treat the document as a build artifact and simply not include it in the repository. – a544jh Aug 08 '21 at 18:31
-
2This is discussed [here](https://tex.stackexchange.com/q/455396) and I think some of the comments in the answers might answer your question, or confirm that it isn't possible. – TTT Aug 09 '21 at 00:05