git

How to use git as root with your SSH keys and Git name and email.

Submitted by luxian on Sun, 01/14/2018 - 01:56

This is definitely not best practice, but on some servers I have some server configuration in Git and I deploy and update them manually. Git is used more as versioning system and less for deployment.

There are two main issue with this approach once you switch to root account (sudo su):

  1. you loose you ssh key chain and you can not pull/push changes
  2. if you commit changes, your Git name and email are empty and using git config it's not OK since multiple users might do the same thing

It's possible to fix this using sudo by using something like this:

 

sudo -Es GIT_AUTHOR_NAME=Your\ Name GIT_COMMITTER_NAME=Your\ Name GIT_COMMITTER_EMAIL=your.email@example.com GIT_AUTHOR_EMAIL=your.email@example.com su
I added an alias for this and whenever you use the alias, you will forward your ssh key chain and set Git username and password by send temporary environment variables.

How to commit whitespace and coding standard changes in legacy code

Submitted by luxian on Tue, 07/25/2017 - 07:38

The project I'm working on has inconsistency issues when it comes to coding style. Even though it's a Drupal project, it doesn't follow Drupal's coding standards and on top of that the .php files are saved using various character encoding and line endings. This forced me to develop a workflow that I use before changing legacy files which helped me to keep changes history readable.

Committing together a file encoding change, white-space conversion and a bug-fix will be a source of regret if you ever have to look at that diff again. Most likely you will pull your hair out trying to figure out what is a code change and what's only a code style fix. That's why I separate the coding standard fixes in a single commit before doing anything else. This commits will be easy to ignore when checking history and can provide a cleaner diff for the changes that follow.

The steps I follow are:

Tags