Reader small image

You're reading from  Python Scripting in Blender

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781803234229
Edition1st Edition
Right arrow
Author (1)
Paolo Acampora
Paolo Acampora
author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora

Right arrow

Version control and backup

Version control helps to keep track of file changes, save snapshots of the code, and roll back to older versions if necessary. Git is the most used versioning system at present; it is free and integrated into most editors. In this section, we will use version control in combination with VS Code.

Initializing the repository

Once Git is installed, it can be used from VS Code, by activating the Source Control tab using the branch icon on the left column bar. The Initialize Repository button adds versioning to our folder:

Figure 1.25: Adding version control in VS Code

Figure 1.25: Adding version control in VS Code

The icon will change and warn us about the presence of files. We click the + icon next to the filename to add them to versioning. In Git terminology, we are going to Stage the current changes:

Figure 1.26: Staging changes in VS Code

Figure 1.26: Staging changes in VS Code

The editor shows the before/after conditions of our files. We can add a message in the text field on the top left and click the tick icon. This will Commit our changes to the project history:

Figure 1.27: Commit changes in VS Code

Figure 1.27: Commit changes in VS Code

Making changes

Let’s say we don’t want our script to delete the current objects. To do that, we delete line number 13:

bpy.ops.object.delete(use_global=False)

When the file is saved, version control detects this change. We can stage that by clicking the + icon, as before. If we select OurFirstScript.py in the left column, VS Code highlights the current changes. We add a message for this new commit and click the tick button again:

Figure 1.28: Displaying changes in VS Code

Figure 1.28: Displaying changes in VS Code

If we go back to the Explorer tab and select our script, we will see that a section called Timeline can be expanded: it contains a list of our commit messages. Selecting a commit displays the related changes, allowing us to restore old lines of code. Every change that is not committed can be easily undone using the Revert function.

Reverting uncommitted changes

Let’s add some incorrect text at line 7 and save. If, for any reason, we cannot undo that, we can right-click our file in the Version Control tab and select Discard Changes:

Figure 1.29: Discarding uncommitted changes in VS Code

Figure 1.29: Discarding uncommitted changes in VS Code

The importance of version control can be underestimated at first but becomes vital in more complex projects. It’s a wide topic that goes beyond the scope of this book, but it’s important to grasp at least the basics of it.

Previous PageNext Page
You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023Publisher: PacktISBN-13: 9781803234229
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Paolo Acampora

Paolo Acampora is a 3D artist and programmer, with experience in Animation, Visual Effects, and Real Time computer graphics. He provides tools that streamline the production workflow and let artists focus on the creative aspects of their craft. He has worked with several studios for more than a decade. He contributes to the blender development and releases his tools for the community.
Read more about Paolo Acampora