Thursday, December 19, 2013

Git most used features

Cache credentials if you need to enter credentials only once and they are cached for 900 seconds
git config credential.helper 'cache --timeout=3000'
Create branch from an existing branch and switch to it
git checkout -b new_branch develop
Create branch from commit and switch to it
git checkout -b new_branch d9410d98f69d08
Diff between local and remote branch
git fetch
git difftool origin/develop develop
# to refresh develop branch
git pull
Delete branches that don't exist on remote repo - sync remote and local repo
# git remote prune origin
* [pruned] origin/branch_name
# git branch -d branch_name # manually remove orphan
comparing files in two revisions
# this will launch diff tool for one file in two revisions
$ git difftool 344c f8cc proba.txt

# this will launch diff tool for one file in commit and working directory
$ git difftool  a9a5f2a ./component.ts

# Usage of difftool for comparing all files in two revisions
git difftool 8c6a dd6b
Compare current commit with previous one
git difftool HEAD..HEAD~1
Put in zip archive files from single commit
git archive -o latest.zip HEAD
My favorite format for log
git log --pretty=format:"%C(#cd9a00)%h %C(#0080ff) <%an> %C(#17b062)(%cr) %d %C(#c0d6de)%s"
remove ajax.php from version control but not from file system
git rm --cached ajax.php 
git commit -m 'removed ajax.php from git'
put file from past commit to index and view diff.
git checkout 42cf1ad -- package.json
git difftool --cached
Search every branch in Git Repository and find commit containing messageb or regex search fin.*me in specified time range and print hash, line number and lines around matching line.
# in PowerShell and Linux
git grep -in -C 1 messageb $(git rev-list --all)
git grep -in -C 1  fin.*me $(git rev-list --all --since="2021-05-10" --before="2021-05-26")
another useful when looking for source code in all branches
# search in all files in all branches
# only Linux
git rev-list --all | (
    while read revision; do
        git grep -F 'yourWord' $revision
    done
)
to find branch with SHA
$ git branch -a --contains 08d70aa131ded0ca84f9d31b7
newmain
search all commit messages in all branches
git log --all --oneline | grep "yourWord"
How single file changed in past by time and between commits
git log --follow -p  --since="2 hours ago"  -- README.md
git log --follow -p  HEAD~3..HEAD -- README.md
List commits for my_branch since it's creation
git log --pretty=format:"%C(#cd9a00)%h %C(#0080ff) <%an> %C(#17b062)(%cr) %d %C(#c0d6de)%s" master..my_branch
Solve conflict, merge and refresh feature branch from master
git checkout -b my-branch # create new branch from master
# modify line, commit & push
# in GitLab modify same line add commit on master 
# create merge request, try to merge it - it fails
git checkout master
git pull # refresh local copy
git checkout my-branch
git merge master
# merge, commit & push
# merge my-branch into master in GitLab using merge request
Install diff and merge tool for Windows: 1.Install KDiff3 2.Place this in .gitconfig file
[difftool "kdiff3"]
    path = "c:/Program Files/KDiff3/kdiff3.exe"
    trustExitCode = false
[difftool]
    prompt = false
[diff]
    tool = kdiff3
[mergetool "kdiff3"]
    path = "c:/Program Files/KDiff3/kdiff3.exe"
    trustExitCode = false
[mergetool]
    keepBackup = false
[merge]
    tool = kdiff3

Saturday, December 7, 2013

jQuery animate and queue

Simple HTML with two div elements that shows jQuery's animate and queue effects.

Yellow paragraph simultaneously changes height and width.
Grey paragraph first changes height and then width.

Monday, November 11, 2013

Nesting with columns named id and parent_id

Create table mytable :

CREATE TABLE IF NOT EXISTS `mytable` (
  `id` int(11) NOT NULL,
  `parent_id` int(11) NOT NULL,
  `name` varchar(256) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `mytable`
--

INSERT INTO `mytable` (`id`, `parent_id`, `name`) VALUES
(1, 0, 'item 1'),
(2, 1, 'item 2'),
(3, 2, 'item 3');

And then run following script

Sunday, August 18, 2013

Connecting Two Derived Table

You want to join results from two queries - the derived tables are solution for you.
Look at code below.Yellow highlighted lines are queries that you want to join and green highlighted

Thursday, July 18, 2013

Execute Linux Commands from Browser

If you need to execute a shell command using browser here's how to do it. To understand this tutorial you need to have advanced level of understanding of Linux and PHP.

Wednesday, July 10, 2013

PHP debugging with JavaScript Console, Error and Access Log

You can use JavaScript console to output global and other variables from your PHP file. That way you can use JS console to track what is is going on in PHP backed files that are called by $.ajax. Also you should be familiar with PHP's functions utf8_encode and utf8_decode

Raw outuput of JSON string and Base64 encoded JSON string

Sunday, July 7, 2013

JSONP Tutorial

This is an advanced tutorial with working example you must know jQuery and JSONP foundations. JSONP bypass browser's "same origin" policy.