BookmarkSubscribeRSS Feed

DevOps Applied to SAS Viya 3.5: Revert Changes with Git

Started ‎07-02-2020 by
Modified ‎09-07-2020 by
Views 2,340

You embraced DevOps, you developed new SAS code, modified content, introduced new features, explored new options and got carried away. And now you have an error you cannot fix. How do you revert to a previous working state? If you think you need to remember everything you did, and undo, think again. One of the lesser understood aspects of Git is how easy it is to get back to where you were.

Problem

You are using Jenkins. Your SAS code and content is stored in a source control management (SCM) system. And you are now at, let’s say, build 112.

 

1020-current-build-1024x436.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

You would like to revert to a previous build 104.

 

1030-revert-build.png

 

Have you ever wondered why DevOps forces you to use a Source Control Management system (such as GitLab, GitHub, etc.)? Or all the fuss was about the commit messages you had to write? Read further for the answer.

(Simple) Solution: git revert

Clone a fresh copy of your Git repository locally

In this example, you are on a Linux machine called sasviya01. You will clone the repository locally.

 

# Initialize the git repository before saving there
# Empty devops folder if it exists
cd $HOME
pwd
rm -rf devops
# Create the folder
cd $HOME
pwd
mkdir $HOME/devops
chmod -R 755 devops
cd devops
ls -l
GITPROJECT="insert your git project URL here"
git clone http://intviya01.race.sas.com:980/$GITPROJECT
 
cd PSGEL250-devops-applied-to-sas-viya-3.5
ls -l

Display the latest commits: git log

The Git Log tool allows you to view information about previous commits to your repository.

 

git log -n 10 –oneline

 

The log shows:

 

cc51526 demo 5.6
265b749 demo 5.5
3aa9fce demo 5.4
d85ec1e demo 5.2
b17db23 demo 5.2
d437d2a demo 5.1
dba3a62 demo 5
c4510c5 Revert "demo 4 new report"
5024d6a Merge branch 'cherry-pick-2b87a941-2' into 'master'
51760d1 demo 1

 

Have you have been thorough and wrote meaningful messages when you committed the changes?

 

If you haven’t been, and wrote ‘qwerty…’ or ‘aaa...’, you have just found out what the Commit message was for…

 

If you have been, then you can link commit  ‘demo 1’ with your Jenkins ‘Build 104’.

 

To revert back to ‘demo 1’ you need its id, 51760d1.

git revert

git revert 51760d1 --no-commit

Re-confirm with git log

git log -n 10 --oneline

The log will confirm the revert:

 

51760d1 demo 1
cc51526 demo 5.6
265b749 demo 5.5
3aa9fce demo 5.4
d85ec1e demo 5.2
b17db23 demo 5.2
d437d2a demo 5.1
dba3a62 demo 5
...

Stage and commit the changes

git add .
git commit -m "reverted to demo1"

 

The log might look like:

 

[master 8a0ab3c] reverted to demo1
…
2 files changed, 583 insertions(+), 725 deletions(-)
rewrite Data-Management/contents/StarSchemaReport.json (98%)
rewrite Jenkinsfile (94%)

Push changes remotely

Last step:

 

git push origin master

Check the changes

If you set a webhook between the Git repository and your Jenkins pipeline, the latest push triggered a Jenkins build. The latest build will now be 113 (112+1). Check the pipeline, it has the same content as the build 104 you reverted to.

 

1010-Reverted-build-1024x463.png

Conclusions

Write meaningful commit messages.

Use git log to identify the list of commits.

Use git revert to travel through time to the desired commit.

If other developers might be working on the same project, at the same time, consider a different technique, such as new branch from the old commit and merge request.

DevOps Applied to Viya 3.5 Posts

Want to Learn More about Viya 3.5?

Thank you for your time reading this post. Please comment and share your experience with Jenkins, git and SAS.

Version history
Last update:
‎09-07-2020 09:30 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags