Thursday, January 24, 2013

GIT: reverting a second commit of the push from central repository

Have you ever come across the issue, where you have pushed your code to a central repository but unknowingly old commit also has been pushed which is not required any more.

In general, If you want to revert a last commit:

$ git revert d768b8d6a709ba5524e2cf68915d718b9e9ae0bf


In your last push, you have pushed two commits and imagine second commit now you want to roll back,

$ git revert a768b8d6a709ba5524e2cf68915d718b9e9ae0be

fatal: Commit 137ea95 is a merge but no -m option was given.


You will come across above issue,

To resolve that, we need use -m option with order of a commit. Like below,

$ git revert a768b8d6a709ba5524e2cf68915d718b9e9ae0be  - m 2

This will revert second commit which you have made.

Source:  http://gitready.com/intermediate/2009/03/16/rolling-back-changes-with-revert.html



Tuesday, January 22, 2013

Eclipse debug configuration setting and reading

 Here is the way to specify the debug configuration parameters through VM arguments in eclipse.



In VM arguments section, as you can see I have passed following debug parameter.
-Dkony.debug=true


These parameters I can read in the following way in Java.

String isdebug = System.getProperty("kony.debug");
Boolean DEBUG_MODE = new Boolean(isdebug);

if(DEBUG_MODE) {
        System.out.println("My application is running in debug mode");
      //Do your action here!!
}


Other sources:
http://www.avajava.com/tutorials/lessons/whats-the-difference-between-program-arguments-and-vm-arguments.html








SAXON: Failed to compile stylesheet. 1 error detected.


What would be a reason to come across this issue ? There are several..

Tue Jan 22 17:10:38 IST 2013
Failed to compile stylesheet. 1 error detected.

javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:176)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:91)
at com.kony.sync.offlineservices.util.TransformUtil.transform(TransformUtil.java:35)
at com.kony.sync.ide.actions.GenerateOfflineServicesAction$GenerateOfflineServicesJob.run(GenerateOfflineServicesAction.java:105)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


Since, I don't have log for what had happened internally it was very difficult to figure it out the actual cause by looking at the above issue.

Finally, i figure it out that it was because of '*.xslt' does not exist in the specified location.

Other reasons from various sources:
http://zvon.org/xxl/XSLTutorial/Output/example11_ch15.html






Friday, January 18, 2013

Very useful Eclipse Debug option:Suspending Threads


Suspending Threads


This would be useful If incase eclipse is blocked and you exactly don't know the reason why call is blocking. You can just go to eclipse debug mode and suspend the main thread and worker threads. That will show you the stack frame.
To suspend an executing thread:
  1. Select the thread in the Debug View.
  2. Click the Suspend button [ Suspend ] in the view toolbar.
The thread suspends its execution. The current call stack for the thread is displayed, and the current line of execution is highlighted in the editor in the Debug Perspective.
When a thread suspends, the top stack frame of the thread is automatically selected.  The Variables View shows the stack frame's variables and their values.  Complex variables can be further examined by expanding them to show the values of their members.
When a thread is suspended and the cursor is hovered over a variable in the Java editor, the value of that variable is displayed.

Thursday, January 17, 2013

Stashing your changes


Stashing is a great way to pause what you’re currently working on and come back to it later. For example, if you working on that awesome, brand new feature but someone just found a bug that you need to fix. Add your changes to the index using
git add .
Or add individual files to the index, your pick. Stash your changes away with:
git stash
And boom! You’re back to your original working state. Got that bug fixed? Bring your work back with:
git stash apply
 
  You might have stashed more than one, now you want to get the last one.

   git stash pop

   






GIT: How to reset your local branch to master branch


Imagine you have made few local commits and you don't want to commit all of them. Instead you want to go back to the master branch state.
git reset --hard origin/master     // This won't work!

Setting your branch to exactly match the remote branch can be done in two steps
git fetch origin
git reset --hard origin/master

If you want to save your current branch's state before doing this (just in case), you can do:
git commit -a -m "Saving my work, just in case"
git branch my-saved-work


Merging from one branch to other branch


Merging all the commits from one branch to another branch.

For example, currently I am working with 5.5 branch for new features and wanted to pull the changes from 5.0 for fixes which are made.

Currently my branch is pointing to Dev-5.5
$ git merge Dev-5.0

If you have all the 5.0 changes in local system, above command will work fine. 
If your local Dev-5.0 branch is not up-to-date, first pull the changes from central repository.

$ git checkout Dev-5.0

Now you are in Dev-5.0 branch.

$ git pull origin Dev-5.0

This will fetch all the latest commits from origin/Dev-5.0 to local Dev-5.0 branch.

Now, go back to Dev-5.5 branch, to where you want to merge.

$ git checkout Dev-5.5

Now, you are in Dev-5.5 branch.

$ git merge Dev-5.0

This merges Dev-5.0 commits to Dev-5.5 branch, if none of the files having conflicts.

If any file is having conflict, merging will be failed and shows the conflicted files in the console.

Go to the specific files and resolve the conflicts.

Once conflict is resolved, add that file and commit them.

$ Git add hello.java // this is my conflicted file.

$ git status // this will show all the files still need to be merged and including with conflict resolved file.

$ git commit // remaining things are as usual.