Wednesday, December 14, 2011

How to restore locally deleted file in git

If you have not committed yet then find the last commit 
git rev-list -n 1 HEAD -- <file_path> 

Then checkout the version at the commit before.
git checkout <deleting_commit>^ -- <file_path>

How to see list of tags for a git repo

To see list of all tags for a git repo, run command
git tag

To also see the commit message along with the tag, run command
git tag -n

How to push tags in your local git repo to remote

Following command pushes all tags from local git repo to remote
git push --tags


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!