0

Steps to setup git notify emails

1. chmod a+x /usr/share/doc/git-core/contrib/hooks/post-receive-email
2. cd ~/your-project-repository/.git/hooks/
3. ln -s /usr/share/doc/git-core/contrib/hooks/post-receive-email post-receive
4. cd ~/your-project-repository/.git/
5. open config file
6. add the following code
   [hooks]
        mailinglist = your@email.address,second@email.address
        showrev = "git show -C %s; echo"
        emailprefix = "[Your Prefix] "

When you receive an email after you did a git push, you probably can only see the summary of changes. If you want to see the full details in what you have changed from the last commit, then follow the steps below:

open /usr/share/doc/git-core/contrib/hooks/post-receive-email and go to find the following codes

echo ""
echo "Summary of changes:"
git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev

Here git is asked for the diff, but then it is also asked to summarize it. Remove the --stat and --summary flags and you will see the diff.

git diff-tree --find-copies-harder $oldrev..$newrev

Here is another way that shows all revisions including diffs from $oldrev to $newrev

git --no-pager log --find-copies-harder $oldrev..$newrev

0

migrate SVN with history to a new Git repository

a simple migration with all the history

 git-svn clone svn://svn.url

0

Convert svn repository to hg

hgsvn is a third-party tool dedicated Subversion interoperability. Sources can be found at http://pypi.python.org/pypi/hgsvn/.

Let's say you want to contribute to CPython. You first import a recent chunk of the CPython history (starting from rev 60800 - so that it doesn't take too much time):

 
$ hgimportsvn -r 60800 http://svn.python.org/projects/python/trunk
$ cd trunk
$ hgpullsvn
$ cd ..

You also can do the code below if you want to get full log history from svn:
 
$ hgimportsvn http://svn.python.org/projects/python/trunk

You then have a folder named "trunk" containing both an hg repo (with each changeset mirroring an SVN revision) and an SVN checkout. It has an unique named branch "trunk".

0

Using Mercurial version control system

Here I found a very good article about using Mercurial from

  Amit Kumar Saha on November 20, 2007 (9:00:00 AM)
  
According to its developers, "Mercurial is a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects." Dozens of projects already use the software. Here's how you can get started with some basic version control tasks using Mercurial.
Mercurial is a open distributed version control system. According to Wikipedia, distributed revision control takes a peer-to-peer approach, as opposed to the client-server approach of centralized systems. Rather than a single, central repository with which clients synchronize, each peer's working copy of the codebase is a bona fide repository. Synchronization is conducted by exchanging changesets, which define unique versions of every file, from peer to peer.
Mercurial is good for version control of both personal projects and large-scale enterprise projects.
Installing Mercurial is a breeze. Download the Mercurial tarball, extract the archive, change to the mercurial directory, and run:
$ make
$ sudo make install    # do a system-wide install
$ hg debuginstall      # sanity check
$ hg                   # see help
See the software's Web site for detailed installation instructions and platform-specific notes.
To begin exploring Mercurial, you can work with an existing repository or set up your own. To initialize a new local repository with the name "f00-repo," use the command hg init f00-repo. Note that I said "initialize," not "create"; if the directory already exists, hg initializes a new repository there. Otherwise, Mercurial creates a directory named .hg and then initializes it. Mercurial keeps all the metadata about the repository in this directory.
Once you have a repository, you can tell Mercurial about a file you want to track with the command hg add file1.txt. When you're satisfied with the file, check it in with a comment using a command like hg commit -m "Added new file".
You can view a log of your transactions by using the hg log command:
$ hg log
changeset:   0:4706e1104b96
tag:         tip
user:        amit@ubuntu-laptop
date:        Sun Nov 04 22:31:28 2007 +0530
summary:     Added new file

Cloning and pulling

If you want to create a working copy of a repository for yourself in which you can create, modify, and commit files before you commit them to the parent repository (so that you can keep working even when you are disconnected from the remote repository, or you just want experiment with the code), you can clone an existing repository, specifying the original and your new repository names:
$ hg clone f00-repo f00-repo-1
2 files updated, 0 files merge d, 0 files removed, 0 files unresolved
Other users can do the same thing, leading to disparate versions of files in diverse repositories on the server or the network. Suppose that John's working copy is f00-repo-1 and Jane's is f00-repo-2. If Jane wants to "pull" in the changes that John committed, she can first determine what things will be pulled with the following command:
$ hg incoming ../f00-repo-1
comparing with ../f00-repo-1
searching for changes
changeset:   3:5b2454e51e13
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:43:30 2007 +0530
summary:     Added file2

changeset:   4:8503fe7d3247
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:44:01 2007 +0530
summary:     Added file3

changeset:   5:5a26319e7c66
tag:         tip
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:48:28 2007 +0530
summary:     Added 1 line each
To pull in the changes and update the working copy, she would run:
$ hg pull ../f00-repo-1
pulling from ../f00-repo-1
searching for changes
adding changesets
adding manifests
adding file changes
added 3 changesets with 4 changes to 4 files
(run 'hg update' to get a working copy)

$ hg update
4 files updated, 0 files merged, 0 files removed, 0 files unresolved

Pushing

If, once she's made changes, if Jane wants to pass them along to another user, she can push her changes into someone else's repository. Again, the first step is to check what will be pushed:
$ hg outgoing ../f00-repo-3
comparing with ../f00-repo-3
searching for changes
changeset:   3:5b2454e51e13
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:43:30 2007 +0530
summary:     Added file2

changeset:   4:8503fe7d3247
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:44:01 2007 +0530
summary:     Added file3

changeset:   5:5a26319e7c66
tag:         tip
user:        amit@ubuntu-laptop
date:        Sun Nov 04 23:48:28 2007 +0530
summary:     Added 1 line each

$ hg push ../f00-repo-3
pushing to ../f00-repo-3
searching for changes
adding changesets
adding manifests
adding file changes
added 3 changesets with 4 changes to 4 files
If you're concerned about access control, Mercurial has you covered in threeways:

Remote repositories and other version control systems

Our discussions so far, has dealt only with local repositories. With remote repositories, nothing changes except the repository locations. You just have to specify a URL, which could be a remote Web server, an FTP server, or a domain name.
For example, to clone a remote repository, use the command:
$ hg clone http://selenic.com/hg working-rep0
Mercurial offers tools that provide automatic conversion of repositories from other SCMs to Mercurial. ConvertExtension bundled with mercurial supports branches, incremental imports, and only understands CVS, subversion, Darcs and git. This link will be useful for further information on the topic.
Help is never far away. The project has mailing lists and commercial support available. If you need further help, the book Distributed Revision Control with Mercurial is an excellent resource to have. The Mercurial Web site also lists some HOWTOs.

Conclusion

Mercurial is easy to set up, fast, and lightweight -- as good for your local version control needs as it is for maintaining large projects. Even going public with your repository is not a big hassle -- free Mercurial hosting is available.
Amit Kumar Saha is a student of computer science and engineering from India. He writes about Linux, open source software, and technical topics mainly for beginners, and is also a contributor to a couple of open source documentation projects.

0

Setting up public key authentication over SSH

linux

Generate key on local machine

ssh-keygen -t rsa
It will ask you for a password but you can leave it blank.
Note you could also pick -t dsa if you prefer.

Ensure that the remote server has a .ssh directory

Make sure the server your connecting to has a .ssh directory in your home directory. If it doesn't exist you can run the ssh-keygen command above, and it will create one with the correct permissions.

Copy your local public key to the remote server

If your remote server doesn't have a file called ~/.ssh/authorized_keys2 then we can create it. If that file already exists, you need to append to it instead of overwriting it, which the command below would do:
scp ~/.ssh/id_rsa.pub remote.server.com:.ssh/authorized_keys2

Now ssh to the remote server

Now you can ssh to the remote server without entering your password.

Security

Now keep in mind that all someone needs to login to the remote server, is the file on your local machine ~/.ssh/id_rsa, so make sure it is secure.

0

PostgreSQL Cheat Sheet (to be continued)

= DATABASE =

CREATE DATABASE

CREATE DATABASE dbName;

CREATE DATABASE (command line)

Createdb dbName

DROP DATABASE (command line)

Dropdb dbName;

Backup a database (command line)

pg_dump dbName > dbName.sql

Backup all databases (command line)

pg_dumpall > pgbackup.sql

Restore a database (command line)

psql -f dbName.sql dbName

Restore a database by a specific user (command line)

psql -U username -f dbName.sql dbName

Run a SQL script (command line)

psql -f script.sql databaseName

= TABLE =

CREATE TABLE (with auto numbering integer id)

CREATE TABLE tableName (
 id serial PRIMARY KEY,
 name varchar(50) UNIQUE NOT NULL,
 dateCreated timestamp DEFAULT current_timestamp
);

DROP TABLE

DROP TABLE tableName;

Add a primary key

ALTER TABLE tableName ADD PRIMARY KEY (id);

Add a column

ALTER TABLE tableName ADD COLUMN columnName ;

Create an INDEX

CREATE UNIQUE INDEX indexName ON tableName (columnNames);

Table Maintenance

VACUUM ANALYZE table;

Reindex a database, table or index

REINDEX DATABASE dbName;

= SELECT STATEMENTS =

Search using a regular expression

SELECT column FROM table WHERE column ~ 'foo.*';

The first N records

SELECT columns FROM table LIMIT 10;

Pagination

SELECT cols FROM table LIMIT 10 OFFSET 30;

= PREPARED STATEMENTS =

Prepared Statements

PREPARE preparedInsert (int, varchar) AS
  INSERT INTO tableName (intColumn, charColumn) VALUES ($1, $2);
EXECUTE preparedInsert (1,'a');
EXECUTE preparedInsert (2,'b');
DEALLOCATE preparedInsert;

= FUNCTION =

Create a Function

CREATE OR REPLACE FUNCTION month (timestamp) RETURNS integer 
 AS 'SELECT date_part(''month'', $1)::integer;'
LANGUAGE 'sql';

= MISC =

Show query plan

EXPLAIN SELECT * FROM table;

Import from a file

COPY destTable FROM '/tmp/somefile';

Show all runtime parameters

SHOW ALL;

Grant all permissions to a user

GRANT ALL PRIVILEGES ON table TO username;

Perform a transaction

BEGIN TRANSACTION 
 UPDATE accounts SET balance += 50 WHERE id = 1;
COMMIT;

= SAMPLES=

Get all columns and rows from a table

SELECT * FROM table;

Add a new row

INSERT INTO table (column1,column2)
VALUES (1, 'one');

Update a row

UPDATE table SET foo = 'bar' WHERE id = 1;

Delete a row

DELETE FROM table WHERE id = 1;

0

Indexed Linux Command

An A-Z Index of the Bash command line for Linux.

a  
  adduser  Add a user to the system
  addgroup Add a group to the system

  alias    Create an alias •
  apropos  Search Help manual pages (man -k)
  apt-get  Search for and install software packages (Debian)
  aspell   Spell Checker
  awk      Find and Replace text, database sort/validate/index
b
  basename Strip directory and suffix from filenames
  bash     GNU Bourne-Again SHell 
  bc       Arbitrary precision calculator language 
  bg       Send to background
  break    Exit from a loop •
  builtin  Run a shell builtin
  bzip2    Compress or decompress named file(s)
c
  cal      Display a calendar
  case     Conditionally perform a command
  cat      Display the contents of a file
  cd       Change Directory
  cfdisk   Partition table manipulator for Linux
  chgrp    Change group ownership
  chmod    Change access permissions
  chown    Change file owner and group
  chroot   Run a command with a different root directory
  chkconfig System services (runlevel)
  cksum    Print CRC checksum and byte counts
  clear    Clear terminal screen
  cmp      Compare two files
  comm     Compare two sorted files line by line
  command  Run a command - ignoring shell functions •
  continue Resume the next iteration of a loop •
  cp       Copy one or more files to another location
  cron     Daemon to execute scheduled commands
  crontab  Schedule a command to run at a later time
  csplit   Split a file into context-determined pieces
  cut      Divide a file into several parts
d
  date     Display or change the date & time
  dc       Desk Calculator
  dd       Convert and copy a file, write disk headers, boot records
  ddrescue Data recovery tool
  declare  Declare variables and give them attributes •
  df       Display free disk space
  diff     Display the differences between two files
  diff3    Show differences among three files
  dig      DNS lookup
  dir      Briefly list directory contents
  dircolors Colour setup for `ls'
  dirname  Convert a full pathname to just a path
  dirs     Display list of remembered directories
  dmesg    Print kernel & driver messages 
  du       Estimate file space usage
e
  echo     Display message on screen •
  egrep    Search file(s) for lines that match an extended expression
  eject    Eject removable media
  enable   Enable and disable builtin shell commands •
  env      Environment variables
  ethtool  Ethernet card settings
  eval     Evaluate several commands/arguments
  exec     Execute a command
  exit     Exit the shell
  expect   Automate arbitrary applications accessed over a terminal
  expand   Convert tabs to spaces
  export   Set an environment variable
  expr     Evaluate expressions
f
  false    Do nothing, unsuccessfully
  fdformat Low-level format a floppy disk
  fdisk    Partition table manipulator for Linux
  fg       Send job to foreground 
  fgrep    Search file(s) for lines that match a fixed string
  file     Determine file type
  find     Search for files that meet a desired criteria
  fmt      Reformat paragraph text
  fold     Wrap text to fit a specified width.
  for      Expand words, and execute commands
  format   Format disks or tapes
  free     Display memory usage
  fsck     File system consistency check and repair
  ftp      File Transfer Protocol
  function Define Function Macros
  fuser    Identify/kill the process that is accessing a file
g
  gawk     Find and Replace text within file(s)
  getopts  Parse positional parameters
  grep     Search file(s) for lines that match a given pattern
  groups   Print group names a user is in
  gzip     Compress or decompress named file(s)
h
  hash     Remember the full pathname of a name argument
  head     Output the first part of file(s)
  help     Display help for a built-in command •
  history  Command History
  hostname Print or set system name
i
  id       Print user and group id's
  if       Conditionally perform a command
  ifconfig Configure a network interface
  ifdown   Stop a network interface 
  ifup     Start a network interface up
  import   Capture an X server screen and save the image to file
  install  Copy files and set attributes
j
  join     Join lines on a common field
k
  kill     Stop a process from running
  killall  Kill processes by name
l
  less     Display output one screen at a time
  let      Perform arithmetic on shell variables •
  ln       Make links between files
  local    Create variables •
  locate   Find files
  logname  Print current login name
  logout   Exit a login shell •
  look     Display lines beginning with a given string
  lpc      Line printer control program
  lpr      Off line print
  lprint   Print a file
  lprintd  Abort a print job
  lprintq  List the print queue
  lprm     Remove jobs from the print queue
  ls       List information about file(s)
  lsof     List open files
m
  make     Recompile a group of programs
  man      Help manual
  mkdir    Create new folder(s)
  mkfifo   Make FIFOs (named pipes)
  mkisofs  Create an hybrid ISO9660/JOLIET/HFS filesystem
  mknod    Make block or character special files
  more     Display output one screen at a time
  mount    Mount a file system
  mtools   Manipulate MS-DOS files
  mv       Move or rename files or directories
  mmv      Mass Move and rename (files)
n
  netstat  Networking information
  nice     Set the priority of a command or job
  nl       Number lines and write files
  nohup    Run a command immune to hangups
  nslookup Query Internet name servers interactively
o
  open     Open a file in its default application
  op       Operator access 
p
  passwd   Modify a user password
  paste    Merge lines of files
  pathchk  Check file name portability
  ping     Test a network connection
  pkill    Stop processes from running
  popd     Restore the previous value of the current directory
  pr       Prepare files for printing
  printcap Printer capability database
  printenv Print environment variables
  printf   Format and print data •
  ps       Process status
  pushd    Save and then change the current directory
  pwd      Print Working Directory
q
  quota    Display disk usage and limits
  quotacheck Scan a file system for disk usage
  quotactl Set disk quotas
r
  ram      ram disk device
  rcp      Copy files between two machines
  read     Read a line from standard input •
  readarray Read from stdin into an array variable •
  readonly Mark variables/functions as readonly
  reboot   Reboot the system
  rename   Rename files
  renice   Alter priority of running processes 
  remsync  Synchronize remote files via email
  return   Exit a shell function
  rev      Reverse lines of a file
  rm       Remove files
  rmdir    Remove folder(s)
  rsync    Remote file copy (Synchronize file trees)
s
  screen   Multiplex terminal, run remote shells via ssh
  scp      Secure copy (remote file copy)
  sdiff    Merge two files interactively
  sed      Stream Editor
  select   Accept keyboard input
  seq      Print numeric sequences
  set      Manipulate shell variables and functions
  sftp     Secure File Transfer Program
  shift    Shift positional parameters
  shopt    Shell Options
  shutdown Shutdown or restart linux
  sleep    Delay for a specified time
  slocate  Find files
  sort     Sort text files
  source   Run commands from a file `.'
  split    Split a file into fixed-size pieces
  ssh      Secure Shell client (remote login program)
  strace   Trace system calls and signals
  su       Substitute user identity
  sudo     Execute a command as another user
  sum      Print a checksum for a file
  symlink  Make a new name for a file
  sync     Synchronize data on disk with memory
t
  tail     Output the last part of files
  tar      Tape ARchiver
  tee      Redirect output to multiple files
  test     Evaluate a conditional expression
  time     Measure Program running time
  times    User and system times
  touch    Change file timestamps
  top      List processes running on the system
  traceroute Trace Route to Host
  trap     Run a command when a signal is set(bourne)
  tr       Translate, squeeze, and/or delete characters
  true     Do nothing, successfully
  tsort    Topological sort
  tty      Print filename of terminal on stdin
  type     Describe a command •
u
  ulimit   Limit user resources •
  umask    Users file creation mask
  umount   Unmount a device
  unalias  Remove an alias •
  uname    Print system information
  unexpand Convert spaces to tabs
  uniq     Uniquify files
  units    Convert units from one scale to another
  unset    Remove variable or function names
  unshar   Unpack shell archive scripts
  until    Execute commands (until error)
  useradd  Create new user account
  usermod  Modify user account
  users    List users currently logged in
  uuencode Encode a binary file 
  uudecode Decode a file created by uuencode
v
  v        Verbosely list directory contents (`ls -l -b')
  vdir     Verbosely list directory contents (`ls -l -b')
  vi       Text Editor
  vmstat   Report virtual memory statistics
w
  watch    Execute/display a program periodically
  wc       Print byte, word, and line counts
  whereis  Search the user's $path, man pages and source files for a program
  which    Search the user's $path for a program file
  while    Execute commands
  who      Print all usernames currently logged in
  whoami   Print the current user id and name (`id -un')
  Wget     Retrieve web pages or files via HTTP, HTTPS or FTP
  write    Send a message to another user 
x
  xargs    Execute utility, passing constructed argument list(s)
  yes      Print a string until interrupted
  .        Run a command script in the current shell
  ###      Comment / Remark
Commands marked • are bash built-ins, these are available under all shells.
“Talk is cheap. Show me the code” - Linus Torvalds