Friday, March 3, 2017

Git Cheat Sheet

A. To List your local branchs :
  •   git branch

B. How to get or fetch a remote  Branch 
   You first need to fetch and check out the remote branc
  •    git fetch remote remote_branch_name (eg :  git fetch origin story2525/mytest_remote_branch)
  • git checkout remote_branch_name


C. How to delete a  Branch both locally and remotely:  

1. Delete the  remote branch   
  •   git push origin :branch_name or
  •   git push origin --delete branch_name

2. Delete a local branch
  •   git branch -d branch_name   (use -D if your branch hasn't been fully merge yet)         

D. How to rename your remote Branch : 

1. Rename branch locally
  • git branch -m old_branch new_branch

2. Delete the old remote branch   
  •   git push origin :old_branch            

3.  Push the new Branch  and update the upstream to point it to the new remote branch.
  •  git push --set-upstream origin new_branch
E. Git Logs :

git log --oneline | grep searchString
git log --pretty=format:"%cn committed %h on %cd"| grep searchString

F. Force Push :
 git push origin refactor/mybranch —force

G: Change the remote
git remote set-url origin <>


H. Ammend message for a committed and pushed changes
 git commit --amend 
To push the changes to the branch (myBranch) on the remote repository (origin) use: 
git push --force-with-lease origin myBranch


H. Reset your branch to origin version, revert all your local commit and changes.
Plese stash your changes before you do it. git stash

git reset --hard origin/yourbranch


 I. undo the last commit and unstage all the files:

git reset HEAD~;

j. Undo the commit and completely remove all changes(Becareful !)


git reset --hard HEAD~;

K. Undo previous merge:
check the previous log :
git log
Then revert back the merge  corresponding to the commit hash
 git revert -m 1
And finally push your changes:
git push

L. Roll Back your git push
git push -f origin last_good_commit_hash:yourbranch

 example : git push -f origin 4d875f7e3e8:develop



Read More...

Sunday, December 18, 2016

How to check if the given string is palindrome (Recursive vs Non-recursive )

palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward, such as "level" or "kayak" or  "amanaplanacanalpanama" 

Following is the program to check if the given string is a palindrome.  



package com.mytech.today;


public class PalindromeClient {


    public static boolean isPalendrome (String s) {

        if(s== null) {
            throw new RuntimeException("null value passed");
        }

        int n = s.length();
        if(n==1) return true;
        else {

            for (int i=0; i < n/2 ; i++) {
                if(s.charAt(i)!=s.charAt(n-i-1)) {
                    return false;
                }
            }
        }
        return true;
    }

    public static boolean isPalendromeRecurrsive (String s) {

        if (s.length()<2) { return true;}
        else if (s.charAt(0)==s.charAt(s.length()-1)) {
            return isPalendrome(s.substring(1, s.length()-1));
        }
        else return false;

    }

    public static void main(String[] args) {
        System.out.println(isPalendrome("levvel"));
        System.out.println(isPalendrome("manaplanacanalpanama"));
        System.out.println(isPalendrome("a"));
        System.out.println(isPalendrome("jptt aefa afdaf"));

        System.out.println(isPalendromeRecurrsive("levvel"));
        System.out.println(isPalendromeRecurrsive("manaplanacanalpanama"));
        System.out.println(isPalendromeRecurrsive("a"));
        System.out.println(isPalendromeRecurrsive("jptt aefa afdaf"));
    }
}

Read More...

Wednesday, June 19, 2013

Replace Line Break and Spaces on Text Area using java script !

A simple way to replace line break and spaces on a text area content can be done simply by replacing the line break value and the space value with the corresponding html tag as following .

function replaceLineBreaksAndSpaces(textValue) {
   textValue = replaceSpaceCharacter(replaceLineBreak(textValue));
   return textValue;
}
   
function replaceLineBreak(textValue) {

    textValue = textValue.replace(/\r?\n/g, ' 
<br />');
    return textValue;

}

function replaceSpaceCharacter(textValue) {

    textValue = textValue.replace(/  /g, ' &nbsp;');
    return textValue;
}

Read More...

Pages

 ©mytechtoday.com 2006-2010

 ©Mytechtoday

TOP