til.

Today I learned!

#9 List all commits history for specific file with git

Assuming the given situation:

  • You work on a large project that has an extensive git commits history and a lot of files
  • You need to debug a certain issue that was caused by a certain file
  • You look at the commits history to see which commit is causing the issue but going through it one by one is like finding a needle in a haystack

Well, you’re in luck. You can use the following git log command

1
$~ git log --follow -- path/to/file.txt

This will list down all the commits history for that specific file. It will work even if the file was deleted or renamed. However please be aware that it will only work for a single file at a time.

#git

#8 How to get the list of all build settings available in your Xcode projects

I learned a command from my senior(Joseph) this week that can print all available build settings available in your Xcode project.

This is super helpful when you have to write a custom run script or when you have to edit a 3rd party library install script (like what I experienced this week 😭)

Anyway, to print the list run the following command in your project root:

1
xcodebuild -showBuildSettings -project SampleApp.xcodeproj

Or if you’re using workspace, use the following command. The -scheme have to be defined for it to work.

1
xcodebuild -showBuildSettings -workspace SampleApp.xcworkspace -scheme 'SampleApp'

If you want the list of build settings that are specific to a certain configuration, ie: Release or Debug

1
xcodebuild -showBuildSettings -workspace SampleApp.xcworkspace -scheme 'SampleApp' -configuration Release

Finally, to make it easier for you to go through the whole list, you can pipe the output to a text file. For example

1
xcodebuild -showBuildSettings -workspace SampleApp.xcworkspace -scheme 'SampleApp' -configuration Release | tee ~/Desktop/build.txt

Then you can file the generated files at ~/Desktop/build.txt

That’s it. Hope you will find this useful when debugging.

#tools #xcode

#7 How to undo a git rebase

Given the following situation:

  • You’re on feature/* branch and you have your latest changes already pushed to origin
  • Now, you want to rebase your feature/* branch with the latest master
  • You type in git rebase master from your feature/* branch
  • You fix all conflicts and finish the rebase
  • OH SHIT SOMETHING’S WRONG I NEED TO UNDO IT BUT HOW?

Okay, take a deep breath and just calm down. Use the following to reset it to your latest origin.

1
$~ git reset --hard ORIG_HEAD

That’s it. This will only work if you haven’t push your changes to origin yet. If you have, then you need to use git reflog

#6 How to setup Jenkins with Docker

Here’s how to setup Jenkins with Docker

  1. Run the following commands in your terminal
1
2
3
4
docker pull jenkins/jenkins:lts
docker run --detach --publish 8080:8080 --volume
jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
  1. The above command will generate a password. Copy said password

  2. Open localhost:8080 and paste in the password

  3. Setup your user account and install suggested plugins.

That’s it!

#tools

#5: How to make smerge available in your command line

smerge is a command line tools for Sublime Merge. To make this tools available in your command line, you have to symlink it. Here’s the command on how to do it for macOS:

1
 ln -s "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge

That’s it. After this, you can easily browse your repo in Sublime Merge just by typing smerge in your CLI.

For Windows or Linux, you can check Sublime Merge’s docs.

#tools

#4: How to install latest node version with nvm

Today I learned how to install or update my Node.js version to the latest stable version with nvm.

To update to the latest stable version, simply run:

1
$~ nvm install stable

This will also set the installed node as the default. That’s it

#tools #node

#3: What is the difference between Docker container and Docker image?

Today I learned the difference between image and container in Docker. An image is a template that can be used to create a container while container is the instances of said Docker images. The container is the one that runs your application.

To explain it in cake term, image is the recipe of the cake and container is the cake itself. You can create multiple cakes based on the same recipe.

To see all the images available, you can run the following:

1
$~ docker images

and to see the container that’s currently running, you can run:

1
$~ docker ps

or if you want to see the list of available containers, run:

1
$~ docker ps -a

That’s it. 🎂

References: 1. https://stackoverflow.com/questions/23735149/what-is-the-difference-between-a-docker-image-and-a-container

#docker

#2: How to install latest stable ruby version with rbenv

Today I learned a simple solution to install the latest stable ruby version with rbenv. If you are using rbenv to maintain your ruby versions but you couldn’t be bothered to keep track of the releases and just want a stable version, you can use the following command:

1
$ rbenv install $(rbenv install -l | grep -v - | tail -1)

This command will get the latest stable ruby release and install it with rbenv install. That’s it.

References: https://stackoverflow.com/questions/30179484/install-latest-stable-version-of-ruby-using-rbenv

#ruby

#1: How to clone git repository with submodules

Today I learned how to git clone a repository that has git submodules inside of it. I realized that when I cloned a project it will clone the parent repo but the submodules will be empty. Here are the steps on how to clone it properly.

If you haven’t cloned the repository yet, you can use --recurse-submodules option:

1
$ git clone --recurse-submodules https://github.com/sample/sample-repo.git

Otherwise, If you already cloned the project then you can use the following command. Run the command inside your git repository.

1
$ git submodule update --init --recursive

This will initialize, fetch and checkout any nested submodules for the repository. That’s it.

#git