VCS Command Guide
I use 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 both good in different ways and I use different VCSs for different projects as appropriate. However, since they 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).
If you notice anything wrong or can fill in any of the gaps, please drop me a note using this form.
Mercurial | Git |
---|
HG Init is a good tutorial, but mercurial is pretty easy (and safe) to use.
| How to use git to lose data should be required
reading for any git user - I've lost data that I really didn't want to lose when using git, so since then I've
always been a bit nervous.
|
Mercurial | Git |
---|
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
# Now breathe sigh of relief
#########################
# 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.
|
Mercurial | Git |
---|
hg clone ${URL}
# Check .hg/hgrc for errors if using
# schemes extension!
|
|
Mercurial | |
---|
hg remove
# Can also use hg addremove
|
|
Mercurial | Git |
---|
hg log
# OR
hg glog # Shows graphical view
# OR, if you REALLY only want to see the
# history of the current revision:
hg log -f
| git log
# WARNING: this hides lots of revisions
# as it only shows the current branch.
#
# This is better:
git log --all
# OR
git log --branches
# (The second one hides refs/tags and
# refs/remotes, so --all is probably safest)
|
Mercurial | Git |
---|
hg diff -c 1
# OR
hg log -pl1
|
|
Mercurial | Git |
---|
| git commit -a
# OR
git add
git commit
|
Mercurial | Git |
---|
hg ci -m "Message" file1 file2
| git add file1 file2
git commit -m "Message"
|
Mercurial | Git |
---|
hg record
# Requires record extension to be enabled
| git add --interactive
# OR
git add --patch
|
Mercurial | Git |
---|
hg pull -u
# OR
hg pull
hg update
| git pull origin master --tags
|
Mercurial | Git |
---|
| git push origin master --tags
|
Mercurial | Git |
---|
| git checkout -b branch-name
|
Mercurial | Git |
---|
| git branch -r
# Without -r it doesn't show branches
# pulled from remote URLs!
|
Mercurial | Git |
---|
# Use .hgignore with first line as:
syntax: glob
|
|
Mercurial | Git |
---|
| # Working directory changes:
git checkout .
# Also changes in index:
git checkout -f
# An alternative (not sure of difference)
git reset --hard
|
Mercurial | Git |
---|
hg backout # Safe: commit a reverse change
# OR
# Make changes
hg ci --amend -m "Updated commit message"
# OR (using mq extension)
hg qimport -r tip # Dangerous
# Make changes
hg qrefresh -m "Corrected message"
hg qfinish -a
# OR
hg rollback # Dangerous and deprecated
# Make changes
hg ci -m "Corrected message"
| git reset --soft HEAD^ # (what else?!)
# Make changes
git add .
git commit -c ORIG_HEAD # (ick)
|
Mercurial | Git |
---|
touch empty-dir/.placeholder
hg add empty-dir/.placeholder
| touch empty-dir/.placeholder
git add empty-dir/.placeholder
|
Mercurial | Git |
---|
hg tag -r REVSPEC TAGNAME
|
|
Mercurial | Git |
---|
hg purge # (Requires purge extension)
# OR
hg purge --all # includes ignored files
| git clean -xf # includes ignored files
|
Mercurial | |
---|
hg log -r 'tagged() and contains("path/to/filename")'
|
|
Mercurial | |
---|
hg log -r 'modifies("path/to/filename")'
|
|