Monday, November 28, 2011

List of all git commands

Following is the list of all git commands available in the latest version of git (As of Nov 2011)
git-add

git-annotate

git-apply

git-archive

git-bisect--helper

git-blame

git-branch

git-bundle

git-cat-file

git-check-attr

git-checkout

git-checkout-index

git-check-ref-format

git-cherry

git-cherry-pick

git-clean

git-clone

git-commit

git-commit-tree

git-config

git-count-objects

git-describe

git-diff

git-diff-files

git-diff-index

git-diff-tree

git-fast-export

git-fetch

git-fetch-pack

git-fmt-merge-msg

git-for-each-ref

git-format-patch

git-fsck

git-fsck-objects

git-gc

git-get-tar-commit-id

git-grep

git-hash-object

git-help

git-index-pack

git-init

git-init-db

git-log

git-ls-files

git-ls-remote

git-ls-tree

git-mailinfo

git-mailsplit

git-merge

git-merge-base

git-merge-file

git-merge-index

git-merge-ours

git-merge-recursive

git-merge-subtree

git-merge-tree

git-mktag

git-mktree

git-mv

git-name-rev

git-notes

git-pack-objects

git-pack-redundant

git-pack-refs

git-patch-id

git-peek-remote

git-prune

git-prune-packed

git-push

git-read-tree

git-receive-pack

git-reflog

git-remote

git-remote-ext

git-remote-fd

git-replace

git-repo-config

git-rerere

git-reset

git-revert

git-rev-list

git-rev-parse

git-rm

git-send-pack

git-shortlog

git-show

git-show-branch

git-show-ref

git-stage

git-status

git-stripspace

git-symbolic-ref

git-tag

git-tar-tree

git-unpack-file

git-unpack-objects

git-update-index

git-update-ref

git-update-server-info

git-upload-archive

git-var

git-verify-pack

git-verify-tag

git-whatchanged;

git-write-tree

How to install git on Linux (CentOs)

Following are the list of command you can execute on CentoOs 5 to install git

yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel;
cd /usr/local/src;
wget
http://git-core.googlecode.com/files/git-1.7.7.4.tar.gz
tar xvzf git-1.7.7.4.tar.gz;
cd git-1.7.7.4;
autoconf;
./configure --with-curl=/usr/local$;
make;
make install;

ln -s /usr/local/src/git-1.7.7.4/git /usr/bin/git

Monday, November 21, 2011

How to export projects out of git archive

You can do this using git archive command

Following code will extract the current checked out branch, create tar and zip it
git archive --format=tar --prefix=<any dir name you want>/   HEAD | gzip >latest.tar.gz

Following code will extract master branch, create tar and zip it
git archive --format=tar --prefix=<any dir name you want>/   master | gzip >latest.tar.gz

Wednesday, November 16, 2011

Converting a Subversion repository to Git

This is an excerpt from page https://37s.backpackit.com/pub/1465067

Converting a Subversion repository to Git

Assuming we’re converting ExampleApp to git:
  1. mkdir /path/to/exampleapp-git.tmp
  2. cd /path/to/exampleapp-git.tmp
  3. git-svn init file:///u/repos/exampleapp --no-metadata --trunk=trunk --branches=branches --tags=tags
  4. git config svn.authorsFile /path/to/authors.txt
  5. git-svn fetch
The authors.txt file mentioned above is the file attached, below. Note that for large repositories, the ‘fetch’ command here can take quite some time (Basecamp took almost an hour and a half).
Once the fetch finishes, we just need to do some cleanup. First, let’s kill all of the remote tracking branches that we no longer need.
  1. git branch -r
  2. git branch -r -d stale-branch stale-branch …
Where “stale-branch” is the name of a remote-tracking branch that we no longer need.
Next, we can run prune to get rid of any orphaned objects, and gc to clean things up:
  1. git prune
  2. git gc
Then, we can repack everything optimally:
  1. git repack -f -a -d --depth=500 --window=500
Finally, we check out any remote tracking branches, so that when we later push to the final repository location, the branches get remembered:
  1. git checkout -b branch-name branch-name
The branch-name is specified twice because the first one is the name you want to give the local branch, and the second is the name of the remote branch you want to track. Do the above for each branch (“branch-name”) that you want to keep.
Note that if the branch that was checked out upon completion of the fetch was not the master (trunk), then you’ll need to use “git branch -m” to rename the current branch to what was actually checked out, and then checkout trunk as master (git checkout -b master trunk).
Once that is done, we can create our new “bare” repository, where we will all push to and pull from:
  1. cd /u/git
  2. sudo -u app mkdir -m 0770 exampleapp.git
  3. cd exampleapp.git
  4. sudo -u app git --bare init --shared=group
Then, we move back to our converted repository, and push it all to our bare repository:
  1. cd /path/to/exampleapp-git.tmp
  2. git push --all /u/git/exampleapp.git
The “--all” flag tells git that we want to push all branches, not just the current branch. Once that is done, you should be able to clone the new repository from your local machine:
  1. git clone ssh://{repo-server}/u/git/exampleapp.git
Done!

Tuesday, November 15, 2011

How to identify, using git cat-file, type of an object in Git by looking at it SHA1 value

All objects in Git have a sha1 value. Git provides a way to inspect a sha1 and tell you the type of object represented by that sha1
git cat-file -t <sha1>

E.g
git cat-file -t 6a00e12055941d688466e68d6880d2bc06f12b55

This command also supports batch mode that will read a list of objects from STDIN. Just run command
git cat-file
to see all options supported by it

How to see contents of objects in git

Following command shows the content of and object in git
git show <sha1 of object>

The sha1 of the object can be found in directory .git/object/[a-z0-9][a-z0-9]/[a-z0-9]{38}. Note that while create subdirectories in objects folder git takes the first 2 letters to create a sub-directory and remaing 38 to name the file that contains the content. In the command above you will have to give full 40 characters 

How to see decompress git objects (in text)

Git maintains all its objects in in .git/objects directory. These files are compressed. To read the text contents of the file, create a file read_git_obj.pl and add folloing code to it

use strict ;
use warnings ;
use Compress::Zlib ;

my $x = inflateInit() or die "Cannot create a inflation stream\n" ;
my $input = '' ;
binmode STDIN;
binmode STDOUT;

my ($output, $status) ;
while (read(STDIN, $input, 4096)){
        ($output, $status) = $x->inflate(\$input) ;
        print $output
        if $status == Z_OK or $status == Z_STREAM_END ;
        last if $status != Z_OK ;
}
die "inflation failed\n" unless $status == Z_STREAM_END ;


This program reads data from STDIN. It can be used as
cat .git/objects/fd/3feaffcc13c86991c5cbe920f006b4e9b5922f | perl read_git_obj.pl