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


Wednesday, November 9, 2016

Git commit single or multiple files

git commit project/config/app.php project/env -m "Test"

Marked yellow are two files, you add more files one by one.

Marked orange is message for this commit.