CGTK

A. Budden

I use all of Bazaar, Mercurial and Git for various different projects.  There is a lot of discussion on the web about which is best; however, in my experience they're all good in different ways and I use different VCSs for different projects as appropriate.  However, since they all work in different ways and with slightly different commands, I often find it hard to remember the right command.  Therefore, I thought I'd make this page, which contains a simple reference for how to do things in each version control system.  There may well be errors (especially in the git commands as I use this least often at the moment).  The Bazaar commands all assume a centralised workflow with "heavyweight" checkouts (also known as bound branches): this is the way I use Bazaar, so these are the commands I know!

If you notice anything wrong or can fill in any of the gaps, please drop me a note using this form.

Task Bazaar (Centralised) Mercurial Git
Start New Project with a copy on a server
bzr init
bzr init-repo --no-trees ${REPO_URL}
bzr push ${REPO_URL}/trunk
bzr bind :push
hg init
hg clone . ${URL}
vim .hg/hgrc
# Enter this:
[paths]
default = ${URL}
# SURELY there must be an easier way to do this!
git init
git clone --bare ../${NAME}.git
cd ..
tar -czf ${NAME}.git.tgz ${NAME}.git
scp ${NAME}.git.tgz ${USER}@${SERVER}:/path/to/location/
ssh ${USER}@${SERVER}
cd /path/to/location
tar -xf ${NAME}.git.tgz
rm ${NAME}.git.tgz
exit
cd -
git remote add origin ssh://${USER}@${SERVER}/path/to/location/${NAME}.git
#########################
# ALTERNATIVE APPROACH: #
#########################
ssh ${USER}@${SERVER}
cd /path/to/location
git init --bare ${NAME}.git
exit
git clone ssh://${USER}@${SERVER}/path/to/location/${NAME}.git
# Ignore warning about empty repository.
Bind to remote branch bzr bind ${URL}
# Done as part of starting project
vim .hg/hgrc
# Enter this
[hooks]
commit.autopush = hg push
# Not possible without some sort of custom hook?
Get a project from elsewhere bzr co ${URL} hg clone ${URL}
# Check .hg/hgrc for errors if using schemes extension!
git clone ${URL}
Add all files bzr add hg add git add .
Look for deleted files # Automatic hg remove
# (can also use hg addremove)

Show differences in working tree
bzr diff
hg diff
git diff
Show differences introduced in latest revision
bzr diff -c -1
hg diff -c -1
git show HEAD
Commit Changes bzr ci hg ci git commit -a
# OR
git add
git commit
Commit Specific Files with Message bzr ci -m "Message" file1 file2 hg ci -m "Message" file1 file2 git add file1 file2
git commit -m "Message"
Commit Specific Changes within File # Can't be done hg record
# Requires record extension to be enabled
# Doesn't allow groups of lines to be split
git add --interactive
# OR
git add --patch
Get the latest changes into working dir bzr update hg pull -u
# OR:
hg pull
hg update
git pull origin master --tags
Push latest changes # Happens automatically with commit hg push git push origin master --tags
Create a new branch bzr switch -b branch-name hg branch branch-name git checkout -b branch-name
Switch back to the main branch bzr switch trunk hg update default git checkout master
List available branches # Difficult! Something like:
ssh ${SERVER} -c ls ${REPO_PATH}
hg branches git branch -r
# Without -r it doesn't show branches pulled from remote URL!
Merge changes from another branch bzr merge ${REPO_URL}/branch-name hg merge branch-name
Show last <N> entries in log
bzr log -l <N>
hg log -l <N>
git log -<N>
Ignore files with a glob syntax # Use .bzrignore # Use .hgignore with first line as:
syntax: glob
# Use .gitignore
Revert changes in working tree bzr revert
# Working directory changes:
git checkout .
# Also changes in index:
git checkout -f
Undo commit bzr uncommit
git revert # ?
Get information about working tree
bzr info
cat .hg/hgrc

Show files that have changed
bzr st
hg st
git status
Get revision information
# Revision Number:
bzr revno
# Revision ID, Number etc (customisable)
bzr version-info
# Revision ID:
hg identify
# ID and Number:
hg log -l 1
# Revision ID:
git rev-parse HEAD
# (No revision number)
Add an empty directory (if required by toolchain)
bzr add empty-dir
touch empty-dir/.placeholder
hg add empty-dir/.placeholder
touch empty-dir/.placeholder
git add empty-dir/.placeholder
Add a new tag to the current revision
bzr tag TAGNAME
hg tag TAGNAME
git tag TAGNAME
Add a tag to a previous revision
bzr tag -r REVSPEC TAGNAME
hg tag -r REVSPEC TAGNAME
git tag TAGNAME REVID
List all tags
bzr tags
hg tags
git tag
Get rid of ignored files
bzr clean-tree --ignored