Thursday, November 19, 2015

Git Made Easy - Part 4

Once I got a problem. I have tried to checkout my master branch dev. But got an irrelevant message. thats given below.

$ git checkout dev
Switched to branch 'dev'
Your branch is ahead of 'origin/dev' by 1 commit.
  (use "git push" to publish your local commits)

My manager give me a quick solution thats given below:

$ git reset --hard HEAD~1

Tuesday, November 3, 2015

Git Made Easy - Part 3

When we want to push any branch, we need to get log files. There are 3 ways to get log files. They are --
1.  git log
2.  git log –stat
3.  git log –oneline

$ git log
commit 2297ac77d75a57aa1760e2e7560fe331e832a644
Author: Rizvi <abu.rizvi@rgroup.com>
Date:   Tue Nov 3 14:37:24 2015 +0600

    Some changes#1

commit 78d5c1ba8efef0ee6c715ab957a1a7a2ae65b3ef
Author: Rizvi <abu.rizvi@rgroup.com>
Date:   Tue Nov 3 13:39:46 2015 +0600

    .gitignore added

Description: “git log” gives commit number, author name, commit date and commit message.

$ git log --stat
commit 2297ac77d75a57aa1760e2e7560fe331e832a644
Author: Rizvi <abu.rizvi@rgroup.com>
Date:   Tue Nov 3 14:37:24 2015 +0600

    Some changes#1

 src/org/generics/MaximumTest.java | 57 +++++++++++++++++++--------------------
 src/org/generics/Test.java        |  9 +++++++
 2 files changed, 36 insertions(+), 30 deletions(-)

Description: “git log --stat” gives commit number, author name, commit date, commit message, name of classes which are changed and number of files.

$ git log --oneline
2297ac7 Some changes#1
78d5c1b .gitignore added
1987f90 Generics features added
b3e47f6 Thread Class newly added
63b4126 Merge pull request #3 from rizvi/br1005#ext

Description: “git log --stat” gives commit numbers and commit messages.

N.B.: If you amend, then git force push.
Scenerio: First br2009 is pushed to master
$ git push origin br2009:master
Then I have not created any branch and worked on same branch br2009. I amend the new code and then push forcibly makes success.

$ git push origin br2009:master  -f

Generics Made Easy - Part 2

Double.compare(d1,d2)
·         d1 -- first double to compare
·         d2 -- second double to compare.

0, if d1 is numerically equal to d2;
<0, if d1 is numerically less than d2;
>0, if d1 is numerically greater than d2.

General Format:
package org.generics;
public class MaximumTestFirst {
        public static void main(String[] args) {
                System.out.println(maximum(7.5, 6.5));
        }
        private static double maximum(double d1, double d2) {
                double max = d1;
                if (Double.compare(max, d2) < 0) {
                        max = d2; // d2 is the largest so far
                }
                return max;
        }
}

Generics Standard Format:
package org.generics;
public class MaximumTestFirst {
        public static void main(String[] args) {
                System.out.println(maximum(7.5, 6.5));
        }
        private static <T extends Comparable<T>> T maximum(T d1, T d2) {
                T max = d1;
                if (d2.compareTo(max) > 0) {
                        max = d2; // d2 is the largest so far
                }
                return max;
        }
}

Converting area:
Method type
double
<T extends Comparable<T>> T
Parameter type
(double d1, double d2)
(T d1, T d2)
Differences
Double.compare(max, d2)
d2.compareTo(max)


Generics Made Easy - Part 1