Skip to content

Tips & Tricks

Hernan Lopes edited this page Dec 28, 2019 · 13 revisions

This file contains tips and tricks commonly used in the runbox7 development.

Common git issues

Some times in the day to day work, git gets in the way. For example after some commits when the code is pushed to github runbox7 account, Travis CI complains about a wrong format git commit message. How should this be fixed ?

This document will try to provide some help for problems the runbox7 developers encounter.

Synchronize your fork with runbox7 master

If you ever need to synchronize your fork with the oficial runbox7 master branch, do the following:

git clone https://github.com/runbox/runbox7.git   #clone the runbox7 project
cd runbox7                      #move into runbox7direcrory
git remote add upstream https://github.com/runbox/runbox7.git
git checkout master             #checks out the master branch from user repo
git pull origin master          #pull from repo to sync master branch
git fetch upstream              #fetches the "upstream" (runbox7 oficial repo)
git rebase upstream/master      #rebases master with the upstream/master branch

Clone someone else repo and merge into your repo

This happens when someone forks a branch from your project, makes some commits and you want to merge those into your branch.

cd runbox7
git remote add upstream-target_user https://github.com/target_user/runbox7.git #add upstream for target_user
git fetch upstream-target_user               #fetches target_user repo updates
git checkout -b target_user_branch           #create a localbranch
git rebase upstream-geir/target_user_branch  #rebase my branch with "upstream-target_user"/runbox7-feature-profiles branch

start the development server

cd runbox7
RUNBOX7_ANGULAR_BACKEND_HOST='https://localhost/' ./node_modules/.bin/ng serve --poll=2000 --live-reload --progress --watch --aot --proxy-config backend-proxy-remote.conf.js runbox7

npm server does not start

Sometimes, the development server does not start. Try the following command and start the server again

npm ci

Before commit

Its important to verify that linting is correct before the git push. Otherwise Travis CI will complain. Run the following command to check lint and make sure travis will pass the reuslts.

npm run lint

Lint one part of the ci-tests.

Before push

To make sure travis will not throw some error in your code, run the ci-tests locally before a git push

npm run ci-tests

Another part of ci-tests is the headless browser tests which can also be run manually via the command:

CHROME_BIN=chromium-browser npm run test -- --watch=false --progress=false --browsers=ChromeHeadlessCI

Travis CI complains the commit messages are in the wrong format

Suppose you made lots of commits with wrong messages and now travis complains that commit messages are in the wrong format. There are a couple of ways to solve this problem. One way to do this, use git log to list the latest commits and find the last good one. Then reset soft to that commit id. then commit everything again with the correct commit messages.

git log
git reset --soft $commit-id   #this will "uncommit" but keep the changes until that commit. 
                              #It will allow you to commit the changes again. 
                              #Use the correct format this time
git status .
git commit -m 'feat(Something): Correct message format' ....
git push origin $branch_name$
git push --force origin $branch_name$ #force may be needed to overwrite the changes commited

Of course there are other solutions for this. Another solution is to use rebase with "reword" as the example below:

How to change old git commit and modify only the git commit message

  1. Use git log to count how many commits until the wrong commit message
    git log
  1. rebase to that head:
    git rebase -i HEAD~n     -- where n is from step#1
  1. it will open the commit messages ie.
    pick ababe2 One commit message here
    pick beefba Another commit message       <- want to change this one
  1. it needs "pick" to be change to "reword"
    pick ababe2 One commit message here
    reword beefba Another commit message       <- changed from "pick" to "reword"
  1. it will ask to edit the commit message. change, save and done.

Modify the last commit message

If you want to change the last commit message, and you have not pushed yet, you can use ammend.

git commit --amend                                 # git will ask the user to enter a new commit message