Wednesday 30 January 2013

How to undo your local git commit

Suppose if you are planning to do undo changes your local commit this article will help you about that process.

If you committed some files and you made some commit messages after that if you are planning to do undo those commits because you did something wrong in the commit(may be you added unwanted files or changes which raise some errors). Before doing undo your local commits you have to think which ways you want that.

If you are planning undo local commit entirely whatever you changes you did on the commit, if you dont worry anything about that just do the following command.

git reset --hard HEAD^1 (This command will ignore your entire commit and your changes will be lost completely from your local working tree).

If you want undo your commit but you want changes you did on the commit into staging area(before commit just like after git add called staging area) then do the following command

git reset --soft HEAD^1

Now your committed files comes into staging area suppose if you want to unstage the files because you need to edit some wrong conent than do the following command

git reset HEAD

Now committed files comes into staged area into unstaged area now files are ready to edit so whatever you changes you want go edit and added it and make a fresh/new commit.

Hopefully this article helps you about how to undo your local git commit (not committed into remote repository).

Monday 21 January 2013

undefined method to_i in rails 3.2.11 upgrade

I created my rails application using Rails 3.2.3 version. After some period i come to know Rails 3.2.3 having some security issues, Here i have mentioned what is the issue

What is the exact security issue in Rails 3.2.3

People told that if we upgrade rails 3.2.3 into rails 3.2.11 issue will resolve otherwise we have to do some code tweaks for supporting rails 3.2.3 code base.

So we upgrade into rails 3.2.11. Now security issue was over But found some other issue called "undefined method to_i" error in few of the places. After search in Google, we come up with solutions

In rails 3.2.3
doctor = Doctor.first
patient = Patient.new
patient.doctor_id =doctor (Right side Object assignment is valid)
patient.save! (valid)

In rails 3.2.11
doctor = Doctor.first
patient = Patient.new
patient.doctor_id = doctor (Right side Object assignment is invalid)
patient.save! (invalid)
NoMethodError: undefined method 'to_i' error we got this kind of assignments.

patient.doctor = doctor (is valid both left and right side are object reference)


So conclusion is we must use wherever _id column definition have to use INTEGER type only not just Object assignments. 

Sunday 20 January 2013

How to open multiple files in Vi editor

Suppose if you want to open multiple files in Vi editor than do the following commands

CTRL + W + s - That means it will open the same file(whatever file you opened currently for example if you open one file currently) again and the window split into Horizontally.

CTRL + W + v - That means it will open the same file in vertical manner.

After that if you want to open the new file on splinted window than do the following commands

:e <path of the file name> - It will open new file whatever you mentioned in the path.

Switch between multiple files:

ctrl + w + w - means it will go to next file(next tab). If you keep on pressing, you can easilly navigate which file you want to work.

ctrl+w+(h j k l) - It means it will navigate through you desired position either LEFT DOWN UP RIGHT manner.

How to close the opened multiple files

ctrl - w - o - It means it will close all windows other than current file(cursor located/pointing file).
ctrl - w - c - It means it will close only current window file not rest of them.

Tuesday 15 January 2013

How to delete remote branch in Git

Suppose if you are planning to delete remote branch do the following command might be very useful

git push origin :future_enhancement (Here future_enhancement is my remote branch name)

Note: If you are planning to remote master branch in git repository, might be faced some difficulties while deleting because of master branch is made it as "DEFAULT BRANCH".

Better come out from your master branch, just create any temporary branch/ if you have any other branch switch into that branch. Goto your github.com loggin with your credentials

Click =>"Account settings" link on top right corner on the github.com than Click =>"Repositories" tab from the left side menu than select your repository, there you can see "DEFAULT BRANCH" dropdown from there you have to select some other branches as default than save. Thats it from github.com.

Than you come to your local machine, now try to run the following command,

git push origin:master (Now master branch is deleted from the remote repository).

Thursday 10 January 2013

How to rename your local branch name in Git

Suppose if you are planning to rename your local git branch after sometime checkout. The following command will be useful. For example if you checkout previously "master" branch now you decided want to rename your local branch name than do this

git branch -m master working_copy
Immediately your local branch name is renamed into "working_copy".

NOTE: If you edited,added some files in "working_copy" branch and than you did commit those changes and than if you try to push into master do the following command.
 git push origin working_copy:master

If you do "git push origin working_copy" means it will create a new branch "working_copy" in remote repository with your recent changes(not pushed into Master branch).

Tips: git remote origin show - this command will tell you what are the local branches  linked into which branches in remote repository. It will show the permission on push,pull, merge command specific.

Checkout a branch from github

If you planning to checkout git repository, you have to use git clone command like this

git clone <either ssh url /http url>

If you do the above command,checkout all the branches but normally master branch only will gets initializes. If you want to checkout other branches you have to tell like this...
 
git checkout -t origin/future_branch (for example) - This command checkout the remote branch and your local branch name will be same as remote branch.

Suppose if you want to override your local branch name while you checkout, do the following command

git checkout -t -b enhancement origin/future_branch - Now your local branch name is "enhancement" but your remote branch name is "future_branch".

Wednesday 9 January 2013

Linux Vi editor basic commands

 This article will help you, if you are very beginner in Vi editor in Linux platform.

Here is the list of commands for your reference.

* Cursor movement commands

h - left side single character move
j  - down by one line from current cursor position
k - Up one line above from the current cursor position
l  - Right side single character move

* file Edit commands
  * vi +5 <file name> - It will open the file then the cursor position will stay on line no 5( 5 is just example only)

* Search related commands
  * vi +/string - It will open the file and search the given string after that cursor will stay on first occurrence of the given string.

 *  /<string> - It will find a string in the forward way. If you want to next find then press "n"
 * ?<string> - It will find a string in backward way. similarly if you want to find next then press "n"

* Insertion commands
  o(alphabetical letter) - It will insert one line below the current cursor position.
  O(alphabetical letter) - It will insert one line above the current cursor position.

* Delete commands
  dd - It will delete one line from your current cursor position.
  5dd - It will delete 5lines from your current cursor position.(5 is just example only)

* Copy  commands
  yy - It will copy current cursor line.
  5yy - It will copy 5 lines from current cursor position line.(5 is just example only)

* Paste command
  p - It will paste whatever you copied.

* Word jumping/movement
   w - it will move one word to next word (cursor position will be at starting of the string)
    b - Back to previous word (cursor position will be at starting of the string only)
    e - Move to next word (cursor position will be end of the next word)

* Goto Line no :
 ESC then type :<line no>


NOTE : WHENEVER YOU DO THIS COMMANDS BETTER PRESS "ESC" COMMAND TWICE THAT FOR YOU ARE MAKE SURE YOU ARE IN COMMAND MODE. THAN ONLY THE ABOVE COMMANDS WILL EXECUTE.