Git (Basic)

When you have a renamed file and changed file which should not be added to staging.
git add -A filename
This command will add both the renamed file and old file info.
When you have a deleted file and need to add the file to staging.
git add -u filename
When you want to avoid adding staging some parts in a file,
First, see the changed part
git diff filename
Then,
git add -p filename
s
You can split the changed part
git diff –cached filename

When you want to make a change to pushed commit, first you need to check the commit nubmer by

Then, you can check the file name and reverted part by

You can check diff between commits

You can see the working tree

Git rebase
Edit the commit message the past commit made older than three
Example git commit is like this

so if you git rebase 0e6616c Edited new file
git rebase -i a8d305e
This shows the commit after 0e6616c without including the commit itself. You may notice that the order of the commit is also from older to newer.

To change 0e6616c commit message, you need to change ‘pick’ to ‘reward'(shorthand: ‘r’), and overwrite it.

Then, editor will open immediately, so edit the commit message, and save it.

In case you choose edit mode, you can continue git rebase by git rebase –continue.
Merge a branch without leaving history of the branch using Git rebase
You can merge a branch into another branch without leaving its history using git rebase.
We have the history below on develop branch.

And, the new branch branched off develop has this history.

Then, a newbranch should be merged into develop branch without making newbranch history.

Because the same file is edited, you encounter conflict so resolve the conflict. If it is successful, then you will see

You need to fast-forward merge which only moves HEAD position.

Now develop branch has the history below. (You will not see any merged branch)

Because parent commit is different, the added commits have new id numbers.
Merge a branch branched off another branch into develop using Git rebase –onto
thirdbranch has this history. thirdbranch branched off “Modified the line” of the newbranch. (So the two branch have “Modified the line” commit)

…(same commit with newbranch)
Then, if you want to merge from “Added one more file” and the rest of the commit into develop branch without including “Modified the line” commit which newbranch also has, then you should do,

Then, you should fast-forward marge

*Note: if newbranch doesn’t have a new commit from “Modified the line”, it just says
Already on ‘thirdbranch’
Current branch thirdbranch is up to date.
For more information, you should check out https://git-scm.com/book/en/v2/Git-Branching-Rebasing

foreach loop

foreach loop

This code creates a new variable named links which is an array, and uses foreach statement to loop over each item inside this variables, items array, and it’s giving us the delta for each item, so field has multiple values like tags field. Delta represents which position or which delta that value is, so the first one will be delta[0] and second one will be delta[1], so forth, and item is going to be an actual item, a little chunk of renderable array that is when we look at kpr items.

 

Grid layout and Flexbox

Bootstrap
When you use Bootstrap way, you need a wrapper to make a row

You can use display:inline-block instead of float:left. When a column stick out because it has a longer line, set vertical-align: top; to .item
However, you cannot assign negative margin to item, it aligns to left, so you always need wrapper tag to use this method.
One thing that you can do is select wrapper element more top level one. Then you can add negative margin to it without adding wrapper tag by hooking function on Drupal.
Flexbox
Flexbox gives you more flexibility to grid layout. You don’t need to worry about shrinking column. The browser support is from IE11 and there are some reported bugs.
You can check the bug reports here.
https://github.com/philipwalton/flexbugs
You can also check how Flexbox work in Grid system here.

Browser support
http://caniuse.com/#search=flexbox

JavaScript : putting a function into a variable and executing it

 

This one doesn’t work because test2 function cannot start automatically.

 

This one works because setTimeout start automatically.