Saturday, September 10, 2011

Recover lost commits in GIT

Recover lost commits in GIT:
It's a big day for me!!…I am working with GIT from last 5 days and due to some or other reason I could not push my changes to a central repository.
Generally the process I follow is commit, fetch, rebase and push paradigm everyday to make sure that my workspace is clean and latest. But, today I couldn’t go through complete process due to “fatal: malloc, out of memory “issue while doing the rebase. In the process I lost few commits but I am not sure what had happened.
I tried different options and finally I could manage to recover my lost commits with the following approach.
Please find the screenshot for memory issue.


GIT provides a greater flexibility and it manages commits as a snapshot.  Even though git status command is not saying anything about your commits but it will be there somewhere in your local repository.
Here you go...
Step 1: Check git reflog to see all your commits.
Ø  Git  reflog show

This will show all commits which you have done in your local repository including your lost commits.
Every commit will have a hash id, identify the hash id for your lost commit.
Ex:  Here, my lost commit id is “85123ef”.
Step 2:  Confirm your commit
Ø  Git  show  85123ef
This will clearly show you the description and change id of your commit.

Step 3:  Do checkout for your hash id.
Ø  Git  checkout   85123ef
This will recover your lost commit and take you back to where we were at the beginning.





Working with GIT

 How does it work?
       GIT is a version control system, works completely based on local repository concept. It’s completely different than any other source version control systems like Perforce (I was using this before we migrate to git). It will maintain local repository and central repository and whatever your changes you make to your files will be added to staging Area.
     When you commit your changes it actually records in a local repository as a snapshot and when you push your changes it will be merged with a central repository. Will use fetch concept to get the remote changes to your local repository.

Here you will find a list of GIT commands I generally use it during my development every day. Hope this will help you guys.

1.       Creating a new branch
Ø  git branch  [new branch name] 
Ex: > git branch mylocalJavabranch

2.       Checking existing branches in your local repository.
Ø  git branch
o/p:
    myLocalJavabranch
    javabranch
    Customer-fixes

It will list down all your branches reside in your local repository.

     
3.       Checkout to the branch
Ø  Git checkout  [your branch name]

Ex: git checkout customer-fixes

If you are working with multiple branches. May be you could have created different branches for different features which you have been working with.

4.       Checking the status in your branch- It will show the added files and untracked files.
Ø  Git status

5.       Add unstaged files.
Ø  Git add –all

6.       Commit all your added and modified files to a local repository.
Ø  Git  commit –a  -m “description about your commit”

7.       Fetching from a central repository. It will bring all the modified files from a central repository to local repository.
Ø  Git fetch

8.       It’s always a good idea to fetch and rebase before you push your changes. This will bring all files from repository to your local branch and rebase your local changes on top of it.
Ø  Git rebase  [your remote branch]

Ex: git rebase origin/java

If any conflicts it will try to auto merge the files. If not, user has to merge manually and add that file to staging area so that it will be available for the next commit.

Due to conflicts, if rebase could not continue, use the following command to continue the rebase.
Ø  Git rebase –continue

9.       Push your changes to a central repository.
Ø  Git  push  gerrit  HEAD:refs/for/java

10.   Checking the log history. It will list down all the local commits.
Ø  Git reflog show
                     Every commit will generate a hash id to uniquely identify the commit. To check what you have submitted in that commit use this command.
Ø  Git reflog  [hash id]



Here is the cheat sheet for git @ git-cheat-sheet.pdf


Thanks,
Kondal.

Thursday, September 1, 2011

My favourite eclipse shortcuts

Are you looking for eclipse shortcut keys ??? or Do you want to know how to configure the shortcuts in eclipse?? Then this could be the best post for you !!

These are my favourite shortcuts, I generally use in my development. Hope this helps you guys to increase your productivity.
  1. Ctrl + Space bar – Content Assistance 
It will automatically give you the parameter hints or content assistance. This will help you to develop the code faster and as a developer need not to remember all the methods.
Ex1: Just type “sysout” and hit Ctrl+ Space . It automatically fills up  System.out.println()
Ex2: Just type “System.” and hit Ctrl + Space. It will show the proposals, this includes methods and variables which are possible on the particular element.



2.       Ctrl + 1 – Quick Assist!
Depending on the context this will show the possible actions which are possible on it.



3.       Ctrl + Shift + R.- Open Resource
If you want to open any file quickly without browsing for it in the Package Explorer then this is the shortcut for you. It will open a dialog box that accepts the name of the file you’re looking for. It even accepts wildcard characters.



4.       Ctrl + Shift + T – Open Type
If you want to find a Java class without browsing for it in the Package Explorer use this key, it will open up a dialog box for searching the class.



5.       Ctrl + O – Quick Outline
It shows the quick outline of the class. It will list down all variables and methods which are exist in the class.




6.       Ctrl + O + O – Quick outline with all levels
It shows the quick outline of the class. It includes super and sub classes methods and also variables.


7.       F4  - Hierarchy view
To find out the hierarchy of the class. It will list down all the implemented classes. In hierarchy view, it provides an option to check it’s super classes and subclasses.



  1. Ctrl + Shift + G – Finding the references
To find out the references of the selected element or method. All the results will be shown in the  search view.


  1. Ctrl + D – Deletion
This will delete the selected lines of code.

  1. Alt + Down/Up Arrow  key – Moving the code
For moving the selected code in a very simple way.

  1. Ctrl +T – Outline the hierarchy
To find out the hierarchy of the class. It will show the complete list, this includes super and subclasses.



12.   Ctrl + T+ T – Outline the hierarchy with only super types 
     To find out only super types.


  1. Ctrl + Q – Last edit location
To go to the last edit location. You might be modifying lot of code and suddenly you want to go back to the last edited location.

  1. Hold Ctrl  and Click the hyperlink –
To open the declaration or implementation of the class or method of which you want to see.



15.   Ctrl + F8 – Change Perspective
Quickly if you want to change the perspective then this is the key for you.



  1. Ctrl + Shift+ F  -Code Formatter
Just clean your code by using this. It will adjust the complete code based upon the formatting which you have configured.


It's all upto the developer to configure the shortcut keys. Preference Page will help you to configure these.

Open your Preference page and type "keys" in the search filter it will point to the right place where it will allow you to modify or configure new keys. 

Here is the screenshot for the same.



All the best!!

Thanks,
Kondal