Thursday, December 6, 2012

Some lesser Known Git Commands

Git is a version control system used widely for source code management. But before exploring some less known git commands have a look at some of the most commonly used commands here. Go have a look, I will wait!!!

Ah, You are back. So, lets get into some awesome less known git commands.

Git Short Log :

Get a summarized 'git log' output.
It returns the commit logs grouped by author.

git shortlog  

Git Reverting :

Revert the existing commits and add new changes and commits to the reverted record.
Useful for reverting the faulty commits made.

git revert HEAD~2 
Revert the changes specified by 3rd last commit in HEAD and create a new commit with reverted record/changes.

git revert -n master~4..master~1
Revert the changes specified from 5th Last commit in HEAD to the 2nd Last commit in HEAD  and do not create a new commit with reverted changes.


A graphical alternative to git commit.

git citool

Git Diffing :

Equivalent to diff command in Linux.
Shows the diff or changes between the commits or a commit and a working tree.
Extremely handy for getting to know the changes made to the commit or a working tree.

git diff
For further details for the diff command : Go here

Git Greping : 

Equivalent to grep command in Linux.
This searches your current directory for a pattern and prints the lines matching the pattern.
Extremely helpful for searching a particular keyword or pattern in your working directory.

git grep #define
Searches for the pattern #define in the current working got directory and prints all the lines matching #define.

Git Notes :

Adds, removes, or reads notes attached to objects, without touching the objects themselves.
They are used for adding information to commits which was not available during commiting.

git notes add -m 'Tested by Rajeev N B'

This command adds notes to the last commit. You can also specify the commit you want notes to be added.

git show -s 

Shows the notes added to the commit.

Git Stashing :

Stash your current changes of the directory away in a dirty local directory.
It record your current state and index and takes you back to a clean working directory. It copies your local modifications away.

git stash list

To list the stashed changes away.

git stash apply

To apply the stashed changes.

git stash

To stash the changes to some directory. Equivalent to git stash save

Git Blaming :

This is one of most useful, least known command.
This basically lists what revision or author modified each line of code.

git blame 

Lists a detailed list specifying what revision and author modified each line of code in the file name.

Git Bisecting :

Uses binary search, to find a change that introduced a bug.
Extremely helpful in tracking down the change that had lead to a bug.

git bisect

Has a lot of sub commands and options.
Check the complete explanation here

Git Rebasing :

Forward-port local commits to the updated upstream head.
More can be found here.

That's all for now.
Keep Hacking!!!

For any Doubts/ Clarifications/Feedback write to me @
or Connect me on Twitter @rBharshetty

No comments: