top of page
Search
alexanderskoglund

How to add Git Sha on you KiCad schematic drawing

To keep track of your schematics drawing you probably already use the revision feature. However, this in intended for a "finial" drawing and while you have work in progress together with other (e.g., for reviewing) it is good practice to know exactly which version you send for review. So here is how you put Git's version number into your drawing.


Step #1 - Add the field to you drawing

Open the KiCad Drawing Sheet Editor. Here we add an extra field in the right corner and make use of the format symbol "{COMMENT9}". Add it according to the picture below:

Save the drawing.


Step #2 Use the new drawing

Open up your schematic drawing and open "Page Settings...", select your drawing sheet in the "File:" dialog box. Then add the word "dirty" in comment9 (you could enter anything here, but you must write something in order of this to work).


You should now have a "dirty" drawing.


Do all the changes on the schematics and commit them, e.g.,


> git commit -am"Update the schemtics"

Step #3 - The script

Now to the "magic"; create the following script:

#!/bin/bash

gitSha=$(git rev-parse --short=8 HEAD)

old="comment 9 \\\".*\\\""
new="comment 9 \"${gitSha}\""

command="s/${old}/${new}/g"
sed -i "$command" $1

Save as, "gitsha2kicad.sh", and make it executable:

> chmod +x gitsha2kicad.sh

Then run the script:

>./gitsha2kicad.sh my_schematics.kicad_sch

where "my_schematics.kicad_sch" is the filename of your schematic drawing. Open the schematic file again, and you should see the git sha:



Some explanations


The script runs the command "git rev-parse --short=8 HEAD", which returns the short version, i.e., 8 numbers, of the git sha1. The git sha1 is the unique commit id which is 160 characters long. This is a bit too much for us humans, so we can settle for 8 in our case. Next the script used "sed" to search for the string "comment9" and replace its content with the the short git sha1.


7 views0 comments

Recent Posts

See All

Opmerkingen


Post: Blog2_Post
bottom of page