Jump to content

Resgrp:comp-photo-version control short

From ChemWiki

This is a short summary of this page.

Checking out a repository (hg clone)

$ hg clone existing-repo new-repo

Makes a copy (clone) of the existing-repo and names it new-repo. If new-repo is omitted hg will put the clone in the current directory and name it ./existing-repo. Repository specifications can be in the ssh:// or http:// formats. Useful flags: -u rev to update the working directory to rev rather than the default. -U to not update the working directory at all.

Seeing the state of the repository and working directory (hg status, hg log, hg summary)

$ hg log

Shows all commits to the repository. Useful flags: -v shows full log message and list of changed files for each entry. -r rev shows log for rev (which can be a range).

$ hg stat

Shows altered / added / deleted files compared to working directory's parent; i.e. shows status of working directory. Useful flags: various to limit output to only added / altered / deleted / etc files.

$ hg sum

Shows summary of working directory.

Showing the differences (hg diff)

$ hg diff $ hg diff filename

Shows difference between parent commit and working directory in 'diff' format. With no argument shows diffs for all altered files.

Adding, copying, renaming, and deleting files (hg add, hg forget, hg mv, hg rm, hg cp)

$ hg add filename $ hg forget filename $ hg rm filename $ hg mv old-filename new-filename $ hg cp old-filename new-filename

Add places a newly created file under version control (otherwise it will be listed as '?' unknown in hg stat and will not be committed). Forget reverses an add before it's been committed. Rm removes a file from the working directory and marks it as deleted to version control for the next commit. rm -A to mark a file as deleted after you've already deleted it. Move and copy are similar to add and forget, but allow mercurial to track changes to renamed or copied files.

Committing the changes (hg commit)

$ hg ci

Check in the working directory as a new changeset. User will be presented with a file to edit where they can write a useful and informative message. Use -m to pass message on command line.

Fixing mistakes (hg revert, hg rollback, hg update)

$ hg revert filename $ hg revert -a

Use this command to throw away changes you have made to files. The -a flag reverts "all" files in the working directory. The file(s) are reverted to how they are in the parent changeset. A copy is made of each reverted file into a new file with a .orig suffix.

$ hg rollback

Undoes the last commit. This only works once: that is, you can't do an hg rollback directly after an hg rollback. There has to be an hg commit between rollbacks. If you have pushed or pulled this commit to another repository then rolling it back locally is probably pointless.

$ hg update --clean rev

Similar to hg revert, this returns the working directory to a previous changeset rev. Note that using hg update "without" the --clean flag will do something different.

Collaboration (hg incoming, hg pull, hg outgoing, hg push, hg update)

$ hg incoming repository-location $ hg outgoing repository-location $ hg push repository-location $ hg pull repository-location

These commands interact with other repositories. Incoming (and outgoing) shows which changesets the local (remote) repository has that the other doesn't have. Pull (and push) actually copies the changesets into the local (remote) repository.

$ hg update rev

Update attempts to change the parent changeset of the working directory. If there are no changes in the working directory it will be brought up to date with rev (the tip of the current branch is used if rev is omitted). If there are changes then hg update will either abort (if the --check option is used), discard the changes (if --clean is used, or attempt a merge (if rev is an ancestor or descendant of the working directory parent).

Merging two sets of changes (hg merge, hg resolve)

$ hg merge rev

Merge attempts to update the working directory with all changes between the requested revision and the last common ancestor. Conflicts may arise in files that have changed on both sides of the merge; hg merge may start programs to try to resolve conflicts. Unresolved conflicts are marked in hg merge's output. A working directory cannot be checked in until all conflicts are resolved.

$ hg resolve filename

Resolve may start a tool to try to resolve conflicting files. It can also be used to mark files as resolved (-m flag) or unresolved (-u flag).


Tags (hg tag, hg tags

$ hg tag tagname $ hg tag -r rev tagname $ hg tags

Associate tagname with the parent or given revision. This name can be used wherever mercurial expects a revision identifier. Tags are not local unless marked as such and will be exported to remote repositories on push or pull. hg tags shows all tags known in this repository.

Getting help (hg help)=

hg help shows a list of commands, hg help command shows help for a specific command or concept.