Month: March 2018

A Git Cheat Sheet For That Quick Reminder

A Git Cheat Sheet For That Quick Reminder

Switching from subversion to Git was a paradigm shift that took some getting use to, but looking back now, the switch was worth it. Rather than getting tied to any one Git UI, I wanted to get a grasp of plain old Git and the commands it offers.

With that, I’ve created this Git Cheat Sheet to help along the way.

Cloning a Repository

NotesCommands
clone an existing repositorygit clone "repository-path"
create a new local repositorygit init

 

Branch Management

NotesCommands
list local branchesgit branch
list local and remote branchesgit branch -av
create local branchgit branch "branch-name"
create and checkout local branchgit checkout -b "branch-name"
delete local branch that has had its changes pushed to a remote branch (cannot currently be checked out)git branch -d "branch-name"
delete local branch, ignoring whether or not its changes were pushed to a remote branchgit branch -D "branch-name"
delete local and remote branchgit push origin --delete "branch-name"
checkout branchgit checkout "branch-name"
rename currently checked out local branchgit branch -m "new-branch-name"

 

Handling Changes

NotesCommands
see changes made to local branchgit status
track and stage local changesgit add .
commit staged only with a commit messagegit commit -m "commit-message"
commit unstaged and staged with a commit messagegit commit -a -m "commit-message"
amend changes to previous commit (before pushing)git commit --amend
temporarily stash local changes (resets local branch but preserves changes)git stash
apply previously stashed changes to the current branchgit stash pop

 

Undoing (oops)

NotesCommands
discard all changes in working directorygit reset --hard
reset HEAD to a specific commit and discard local changesgit reset --hard
reset HEAD to a specific commit but preserve local changesgit reset "commit-hash"
discard all changes to specific filegit checkout HEAD
revert commit by applying previous commit changes to HEAD then committinggit revert

 

Tracking History

NotesCommands
show all commits for current HEADgit log
show all commits for current HEAD for given filegit log -p "file"
show all commits that HEAD has pointed togit reflog

 

Fetch, Pull & Push

NotesCommands
grab changes from remote, but don't merge into current HEADgit fetch
grab changes from remote, don't merge, and clean-up remote references (known as pruning, prune)git fetch -p
grab changes and merge into current HEADgit pull
create and track remote branch, push all local changes to itgit push -u "remote" "branch-name"
push all local changes to tracked remote branch for current HEADgit push

 

Merge & Rebase

NotesCommands
merge commits from branch into current HEADgit merge "source-branch-name"
merge commits from source branch into target branchgit merge "source-branch-name" "target-branch-name"
rebase current HEAD onto branch (e.g. make that branch the new base of your changes)git rebase "branch"

 

WordPress Error Thrown: Call to Undefined Function

WordPress Error Thrown: Call to Undefined Function

Suddenly I began receiving a “call to undefined function” error when accessing my website. The admin section worked without issue, and there were no changes to the website aside from the automatic updates, but the website decided to no longer function correctly.

The full error message was as follows:

Error thrown
Call to undefined function lighthouse_posted_on()

The fact that the function lighthouse_posted_on() was in the error message was a pretty great clue: for some reason my theme-specific function was not being found, which points fingers toward the issue being with my theme rather than the WordPress install.

Note: if you’re seeing a WordPress specific function in the error, it’s likely that your automatic install failed and you should try manually installing the latest version again.

Verifying Your Theme Parent Theme

I’m using the lighthouse theme which I customized through child theming. After realizing the issue had to be with my theme, I navigated to Appearance -> Theme in the WordPress admin and noticed a parent/child theme related error at the very bottom stating:

ERROR: The parent theme is missing. Please install the “Lighthouse” parent theme.

This was verified when I looked for the theme and couldn’t find it anywhere. Somehow, the Lighthouse parent theme was deleted!

WordPress conveniently provided a button to download and install the theme again. After doing so, I was able to re-activate my child theme, which immediately resolved the Call to Undefined Function error, making my website accessible once again.