Tuesday, November 15, 2016

GIT: How to show changed made on files on branch by commit

It will display file changes between two commits (file names only):
git diff OLDER_COMMIT RECENT_COMMIT --name-status

It will display file changes between two commits:
git diff OLDER_COMMIT RECENT_COMMIT

It will display file changes between local changes and specific commit:
git diff COMMIT_NUMBER

Monday, November 14, 2016

Git, see list of latest commits

To see list of commits:
git log

List of commits with file name & status:
git log --name-status

List of previous n commits
git log --name-status -n 2

List of commits by author name:
git log --name-status --author=Pritom (Case sensitive)

List of commits search by file name:
git log --name-status -n 2 --author=pritom | grep "Search"

GIT: How to show the changes on specific commit

Type the following to git bash to show all changes:
git show COMMIT_NUMBER

To show difference between a specific file type:
git show COMMIT_NUMBER file_location/file_name

Type following to show file list changed on the commit:
git show COMMIT_NUMBER --name-status

Will output following:
M       location/file_name (Modified)

A       location/file_name (Added New)

Git list all commits for a specific file

Type to git bash:
git log --follow filename

and to quit from list type:
q

Friday, November 11, 2016

Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists

Execute the command below:

rm -f ./.git/index.lock

If you have no other git processes running (which is the normal case), go ahead and delete that file.

Untrack files from git using git bash

This will start ignoring the changes to the file:
git update-index --assume-unchanged path/to/file 

When you want to start keeping track again: 
git update-index --no-assume-unchanged path/to/file 

Now list files that are ignored: 
git ls-files -v 

And with a search options: 
git ls-files -v | grep "file_name_part"

Thursday, November 10, 2016

Php determine if date string is a valid date in that format

Code snippet

function validateDate($date_string)
{
    $date_value = DateTime::createFromFormat('Y-m-d', $date_string);
    return $date_value && $date_value->format('Y-m-d') === $date_string;
}

Some examples

var_dump( validateDate('2016-13-10'));   // false
var_dump( validateDate('20160-13-10'));  // false
var_dump( validateDate('2016-11-32'));   // false
var_dump( validateDate('2017-02-29'));   // false

var_dump( validateDate('2016-11-02'));   // true
var_dump( validateDate('1970-12-21'));   // true
var_dump( validateDate('2017-07-29'));   // true

Online fiddle link