Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Friday, October 24, 2025

Hooked on Git Hooks

A useful feature of git is hooks.  There are two hooks that I find very helpful at my job.  The first is in my local development environment.  We have this simple post-checkout hook:

git rev-parse --abbrev-ref HEAD > www/app/includes/git-branch.cfm

What this does is write the name of the current branch to a ColdFusion file (yes, we still use ColdFusion) that is included on the footer of every page.  So when doing development or testing, we can just glance at the footer of the page to know which branch we are on.

The second is on our staging and production servers.  We have this post-merge hook:

rm -rf .vscode

rm -rf README.md

rm -rf www/app/testing

gitlog=$(git log -1 --pretty=format:"%s")

timestamp=$(date "+%Y/%m/%d %H:%M:%S")

echo "$timestamp  $gitlog" >> git-pulls.log

After we deploy our code using git, this removes unnecessary files and writes a simple log of what was deployed. 

Speaking of code deployments, we keep our process simple for our internal app.  To deploy changes, we simply do a git pull on the master branch.  If we need to back out changes, we have a short bash script for that:

#!/bin/bash

git reset --hard HEAD@{1}

I understand the need for CI/CD pipelines for bigger projects but sometimes the simple solutions are the best.

Tuesday, February 18, 2020

Git Status on Command Line Does Not Match Git Status in VSCode.

A couple of times recently I ran into a situation where VSCode was showing a lot of untracked files in git but the command line was not. Today when I opened up VSCode, it showed over 60 untracked items while the command line only showed 15. It turned out to be a simple misunderstanding on my part.

To demonstrate, I created a new git project with a new subdirectory called new-dir. Inside of new-dir, I created 3 files.

When I run git status on the command line without any parameters, it collapses new directories into single entries.

Command line example

By examining the git output in VSCode, I see now that it is running the command git status -z -u. The -z just terminates each entry in the list with a NUL instead of LF presumably for better parsing. The -u lists out each untracked file individually. And this makes sense because in the source control window of VSCode, you want to be able to see the diff of each file individually.

View of source control panel in VSCode

 
Blogger Templates