author | amit |
Tue, 07 Sep 2010 11:03:27 +0530 | |
changeset 123 | 7a16c80c584d |
parent 96 | bb52cf47e920 |
child 135 | 339230606dc0 |
permissions | -rw-r--r-- |
60
8a36825e21c5
Arithmetic section, typo correction, eg script.
Shantanu <shantanu@fossee.in>
parents:
54
diff
changeset
|
1 |
=============== |
8a36825e21c5
Arithmetic section, typo correction, eg script.
Shantanu <shantanu@fossee.in>
parents:
54
diff
changeset
|
2 |
Version Control |
8a36825e21c5
Arithmetic section, typo correction, eg script.
Shantanu <shantanu@fossee.in>
parents:
54
diff
changeset
|
3 |
=============== |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
4 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
5 |
Introduction |
26 | 6 |
============ |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
7 |
|
96 | 8 |
The following statement from a blog[1](http://karlagius.com/2009/01/09/version-control-for-the-masses/") aptly points usefulness of version control systems: |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
9 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
10 |
"Version control is one of those weird, geeky things that never really gained much ground in non-geek fields, despite the fact that it’s blindingly useful. |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
11 |
|
96 | 12 |
Version control (or source control) is nothing more complex than keeping copies of work as we make changes. On the surface, it’s all straight-forward; make a copy of every file before making any changes to it. That way, if something seriously messes up, one can always fall back to something that worked before, or at least compare the broken copy with one that used to work so one can figure out where it went wrong." |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
13 |
|
96 | 14 |
One probably cooks up their own version control system without realizing it had such a geeky name. For instances files with names oldxxxxxx.py and latestxxxxxx.py. Every time to make some change in a file, one save it with different name then the original one. Luckily there are like, loads of version control systems out there to do this heavy lifting. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
15 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
16 |
Why Use Version Control |
26 | 17 |
======================= |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
18 |
|
96 | 19 |
One of idea behind Version Control Tools was to build onto very first step which can be creating a empty file, or writing a first buggy program for assignment, rather than simply loose it. So here are some more reasons why is automated version control needed: |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
20 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
21 |
- It will track the history and evolution of a project, so one don't have to do it manually. It allows to track what changes where made, when were they made, by whom and why. |
26 | 22 |
- For a team of people working on same project, revision control software makes it easier to collaborate. For example, when people more or less simultaneously make potentially incompatible changes, the software will help them to identify and resolve those conflicts. |
96 | 23 |
- It can help to recover from mistakes. If a change made at some moment of time, turns out to be an error in future, one can revert to an earlier version of one or more files. In fact, a really good revision control tool will even help in efficiently figure out exactly when a problem was introduced. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
24 |
|
96 | 25 |
Most of these reasons are equally valid for the project having one man show, or hundred people. Besides projects, even it can be used to maintain assignments related to one particular subject/course, it will help manage things in way much better way. These tools can be used for better *resources management*. All codes, documents, presentation, assignments related to one course maintained in such a inventory can help avoiding accidental lose of data(deletion) and Internet hosting for version control will make the work immune to local hard-disk crash. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
26 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
27 |
Some of Version Control Tools available and used widely are: |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
28 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
29 |
- cvs (Concurrent Version System) |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
30 |
- svn (Subversion) |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
31 |
- hg (Mercurial) |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
32 |
- bzr (Bazaar) |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
33 |
- git |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
34 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
35 |
Each of above mentioned tools have sets of feature which it offers in unique way. For this session we are going to concentrate on hg (mercurial). After covering the basics of hg, one can easily try other tools, and use what-ever he/she is most comfortable with. |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
36 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
37 |
Learning the Lingo |
26 | 38 |
================== |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
39 |
|
96 | 40 |
Here are some of terms which are going to used through out the rest of session: |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
41 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
42 |
Basic Setup |
26 | 43 |
----------- |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
44 |
|
96 | 45 |
(should we include at all terms used by vcs's other than hg?) |
46 |
||
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
47 |
Repository(repo): |
96 | 48 |
The folder with all the files. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
49 |
Server: |
96 | 50 |
The system with the main(mother) repo. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
51 |
Trunk/Main: |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
52 |
The “primary” location for code in the repo. Think of code as a family tree — the “trunk” is the main line. This is generally what is present on server. |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
53 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
54 |
Basic Actions |
26 | 55 |
------------- |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
56 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
57 |
Add: |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
58 |
Put a file into the repo for the first time, i.e. begin tracking it with Version Control. |
96 | 59 |
Head/Tip: |
60 |
The latest version of the repo(Die Hard 4.1) |
|
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
61 |
Revision: |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
62 |
What version a file is on. |
96 | 63 |
Clone: |
64 |
Creating initial copy of the repo onto a local machine. |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
65 |
Commit: |
96 | 66 |
Committing the changes done to the repo in terms of contents of the files or adding/removing of the files. |
67 |
Logs/History: |
|
68 |
Logs of all the past changes done to the repo. |
|
69 |
Update: |
|
70 |
Updating the local repo with the main one, includes both, adding changing done by us or importing changes done by others. |
|
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
71 |
Revert: |
96 | 72 |
Going back to previous committed state of file. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
73 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
74 |
Advanced Actions: |
26 | 75 |
----------------- |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
76 |
|
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
77 |
Branch: |
96 | 78 |
Create a separate copy of the repo for private use (bug fixing, testing, etc). |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
79 |
Diff/Change: |
96 | 80 |
Finding the differences between two versions of a file. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
81 |
Merge (or patch): |
96 | 82 |
Apply the changes from one branch to another, to bring it up-to-date. |
7
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
83 |
Conflict: |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
84 |
When pending changes to a file contradict each other (both changes cannot be applied). |
eef24e2b0bac
Hand out doc for version contol added.
Shantanu <shantanu@fossee.in>
parents:
diff
changeset
|
85 |
|
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
86 |
Types of Version Control: |
26 | 87 |
------------------------- |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
88 |
|
96 | 89 |
(should we have this part at all?) |
26 | 90 |
Based on how source/code management is carried out in a tool there are two categories of Version Control Systems(VCS): |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
91 |
|
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
92 |
- Centralized VCS: |
96 | 93 |
In this kind of system all the revision control functions are performed on a shared server. If two developers try to change the same file at the same time, without some method of managing access the developers may end up overwriting each others work. Centralized revision control systems solve this problem in one of two different "source management models": file locking and version merging. Both svn and cvs follows this kind of management. |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
94 |
|
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
95 |
- Distributed VCS: |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
96 |
In a distributed model, every developer has their own repo. Diffs, commits, and reverts are all done locally, one needs Internet only to share the changes with others. It makes work faster, handles branching and merging in better way, with less management. hg, bzr and git uses this work flow. |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
97 |
|
15 | 98 |
Get Going with Hg: |
26 | 99 |
================== |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
100 |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
101 |
Why hg? |
26 | 102 |
------- |
15 | 103 |
|
96 | 104 |
- easy to learn and use. |
105 |
- lightweight. |
|
106 |
- scales excellently. |
|
107 |
- based on Python. |
|
15 | 108 |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
109 |
A small point to notice here, hg cant track binary files for changes, one can add them to repo, but wont be able to track changes made to it. And hg considers, odt, pdf files as binary. |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
110 |
|
96 | 111 |
Installation: |
112 |
------------- |
|
113 |
||
114 |
- For Linux based systems, hg is available in most of package management. So for say Ubuntu systems:: |
|
115 |
||
116 |
$ sudo apt-get install mercurial |
|
117 |
||
118 |
will be all you need to install hg. Similarly Fedora users can use yum to install hg. |
|
119 |
||
120 |
- For Windows and Mac OS X systems the setup can be downloaded from http://mercurial.selenic.com/downloads/ and standard installation can be followed. |
|
121 |
||
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
122 |
Getting Started: |
26 | 123 |
---------------- |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
124 |
|
96 | 125 |
After installation is complete lets get started with using. First things first, lets pay our homage to *man* pages as per rituals: :: |
15 | 126 |
|
96 | 127 |
$ man hg |
15 | 128 |
|
96 | 129 |
This will give us manuscript of all the options available with *hg*. We can either look through all of it, or a better way will be to use built-in help system of *hg*. Say to get brief list of all commands, along with a description of what each does we can use :: |
15 | 130 |
|
96 | 131 |
$ hg help |
15 | 132 |
|
133 |
Mercurial Distributed SCM |
|
134 |
list of commands: |
|
135 |
add add the specified files on the next commit |
|
136 |
addremove ----------------------- |
|
96 | 137 |
------------------------------------ |
138 |
heads show current repository heads or show branch heads |
|
139 |
------------------------------------ |
|
15 | 140 |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
141 |
For specific command, just follow the command name after the help. :: |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
142 |
|
96 | 143 |
$ hg help diff |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
144 |
hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]... |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
145 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
146 |
diff repository (or selected files) |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
147 |
Show differences between revisions for the specified files. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
148 |
Differences between files are shown using the unified diff format. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
149 |
NOTE:____________ |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
150 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
151 |
Let there be Repository: |
26 | 152 |
------------------------ |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
153 |
|
96 | 154 |
In Mercurial, everything happens inside a repository. The repository for a project contains all of the files that “belong to” that project, along with a historical record of the project's files. A repository is simply a directory which Mercurial treats as special. |
155 |
||
156 |
There can be two ways to create a repo, either downloading a copy of existing repo available on Internet, or creating/starting a new repo. |
|
157 |
||
158 |
Say we have a directory which we want to bring under version control, so we start a new repository using *hg init*: :: |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
159 |
|
96 | 160 |
$ ls -a circulate/ |
161 |
. .. lena.png pendulum.txt points.txt pos.txt sslc1.py sslc1.txt |
|
162 |
$ cd circulate/ |
|
163 |
$ hg init |
|
164 |
$ ls -a |
|
165 |
. .. .hg lena.png pendulum.txt points.txt pos.txt sslc1.py sslc1.txt |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
166 |
|
96 | 167 |
*.hg* directory indicates that this new dir is now a repo.This is where Mercurial keeps all of its metadata for the repository.The contents of the .hg directory and its subdirectories are private to Mercurial. Rest all files are for the user to use them as they pleases. |
168 |
||
169 |
For getting already existing repo hg uses command *"clone"* :: |
|
170 |
||
171 |
$ hg clone http://hg.serpentine.com/tutorial/hello localCopyhello |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
172 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
173 |
requesting all changes |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
174 |
adding changesets |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
175 |
adding manifests |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
176 |
adding file changes |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
177 |
added 5 changesets with 5 changes to 2 files |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
178 |
updating working directory |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
179 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
180 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
181 |
If clone succeeded, there would be a local directory called localCopyhello, with some files: :: |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
182 |
|
96 | 183 |
$ ls localCopyhello/ |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
184 |
hello.c Makefile |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
185 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
186 |
Every Mercurial repository is complete, self-contained, and independent. It contains its own private copy of a project's files and history. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
187 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
188 |
Creating a branch of existing local repo is very easy via hg using clone command: :: |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
189 |
|
96 | 190 |
$ hg clone localCopyhello newCopy |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
191 |
updating working directory |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
192 |
2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
193 |
|
96 | 194 |
newCopy is exact copy of already existing repo. These local branches can prove really handy at times. It allows keep multiple copies of local branch for different purposes, say for debugging, testing, working version. |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
195 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
196 |
History or Logs: |
26 | 197 |
---------------- |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
198 |
|
96 | 199 |
For the new repo created, first thing which can be tried is to check the logs/history. What changes were made and when and why, answers to all those questions are stored in logs safely. So for the cloned repo the history can be viewed using command *"log"* (following commands are wrt localCopyhello repo). :: |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
200 |
|
96 | 201 |
$ hg log |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
202 |
changeset: 4:2278160e78d4 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
203 |
tag: tip |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
204 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
205 |
date: Sat Aug 16 22:16:53 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
206 |
summary: Trim comments. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
207 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
208 |
changeset: 3:0272e0d5a517 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
209 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
210 |
date: Sat Aug 16 22:08:02 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
211 |
summary: Get make to generate the final binary from a .o file. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
212 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
213 |
changeset: 2:fef857204a0c |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
214 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
215 |
date: Sat Aug 16 22:05:04 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
216 |
summary: Introduce a typo into hello.c. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
217 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
218 |
changeset: 1:82e55d328c8c |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
219 |
user: mpm@selenic.com |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
220 |
date: Fri Aug 26 01:21:28 2005 -0700 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
221 |
summary: Create a makefile |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
222 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
223 |
changeset: 0:0a04b987be5a |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
224 |
user: mpm@selenic.com |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
225 |
date: Fri Aug 26 01:20:50 2005 -0700 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
226 |
summary: Create a standard "hello, world" program |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
227 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
228 |
By default, this command prints a brief paragraph of output for each change to the project that was recorded.The fields in a record of output from hg log are as follows: |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
229 |
|
96 | 230 |
- changeset: This field is a identifier for the changeset. The hex string is a unique identifier. |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
231 |
- user: The identity of the person who created the changeset. |
96 | 232 |
- date: The date and time on which the changeset was created. |
233 |
- summary: The first line of the text message entered to describe the changeset. |
|
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
234 |
|
96 | 235 |
To narrow the output of hg log down to a single revision, use the -r option. :: |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
236 |
|
96 | 237 |
$ hg log -r 3 |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
238 |
changeset: 3:0272e0d5a517 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
239 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
240 |
date: Sat Aug 16 22:08:02 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
241 |
summary: Get make to generate the final binary from a .o file. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
242 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
243 |
*range notation* can be used to get history of several revisions without having to list each one. :: |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
244 |
|
96 | 245 |
$ hg log -r 2:4 |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
246 |
changeset: 2:fef857204a0c |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
247 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
248 |
date: Sat Aug 16 22:05:04 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
249 |
summary: Introduce a typo into hello.c. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
250 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
251 |
changeset: 3:0272e0d5a517 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
252 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
253 |
date: Sat Aug 16 22:08:02 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
254 |
summary: Get make to generate the final binary from a .o file. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
255 |
|
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
256 |
changeset: 4:2278160e78d4 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
257 |
tag: tip |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
258 |
user: Bryan O'Sullivan <bos@serpentine.com> |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
259 |
date: Sat Aug 16 22:16:53 2008 +0200 |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
260 |
summary: Trim comments. |
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
261 |
|
96 | 262 |
-v option with "log" gives some extra details related to a changeset. |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
263 |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
264 |
Making Changes: |
26 | 265 |
--------------- |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
266 |
|
96 | 267 |
Lets follow a simple exercise of *managing letters* using hg. We create a new directory and start revision tracking on it.:: |
268 |
||
269 |
$ mkdir letter |
|
270 |
$ cd letter |
|
271 |
$ touch letter.tex |
|
272 |
$ hg init |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
273 |
|
96 | 274 |
Now lets try to create a local clone of this repository:: |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
275 |
|
96 | 276 |
$ hg clone letter letter-clone |
277 |
updating working directory |
|
278 |
0 files updated, 0 files merged, |
|
279 |
0 files removed, 0 files unresolved |
|
280 |
||
281 |
So here, message says 0 files updated but we have just created a *tex* file inside it. Lets try to see status of our main repository by using *status(st)* command:: |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
282 |
|
96 | 283 |
$ cd letter |
284 |
$ hg st |
|
285 |
? letter.tex |
|
286 |
||
287 |
"?" sign in front of file indicates that this file is alien to hg, as in we have to *add* it to repo by:: |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
288 |
|
96 | 289 |
$ hg add letter.tex |
290 |
$ hg st |
|
291 |
A letter.tex |
|
292 |
||
293 |
So file is now part of repository(A symbol). We *commit (alias ci)* it to repo and make changes effective :: |
|
294 |
||
295 |
$ hg ci -u "Shantanu <shantanu@fossee.in>" |
|
296 |
-m "First commit." |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
297 |
$ hg log |
96 | 298 |
changeset: 0:210664b4ed58 |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
299 |
tag: tip |
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
300 |
user: Shantanu <shantanu@fossee.in> |
96 | 301 |
date: Tue Feb 23 19:41:45 2010 +0530 |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
302 |
summary: First commit. |
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
303 |
|
96 | 304 |
Some arguments passed to *ci* command are worth noticing: |
305 |
- *u* is to provide name and email contact information of person making changes! |
|
306 |
- *m* is to provide one-line summary of changeset. |
|
307 |
||
308 |
If we don't give these options, *ci* will take us to a default editor, there we have to specify a commit *message* in first line, then we can edit other information like username, once done just exit the editor and changes are committed to the repo. Now these changes will be visible in logs. |
|
309 |
||
38 | 310 |
Similar to add there are other commands available for file management in repo. *copy (alias cp)* command is used to mark files as copied for the next commit. :: |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
311 |
|
96 | 312 |
$ hg cp letter.tex letter-prof.tex |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
313 |
|
96 | 314 |
*rename(alias mv)* rename files; equivalent of copy + remove. :: |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
315 |
|
96 | 316 |
$ hg rename letter.tex letter-personal.tex |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
317 |
$ hg st |
96 | 318 |
A letter-personal.tex |
319 |
A letter-pro.tex |
|
320 |
R letter.tex |
|
321 |
$ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Renamed and added letters." |
|
322 |
||
323 |
*tip* command shows newest revision in the repository. :: |
|
324 |
||
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
325 |
$ hg tip |
96 | 326 |
changeset: 1:4a2d973a92de |
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
327 |
user: Shantanu <shantanu@fossee.in> |
96 | 328 |
date: Tue Feb 23 19:50:39 2010 +0530 |
329 |
summary: Renamed and added letters. |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
330 |
|
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
331 |
Sharing Changes: |
26 | 332 |
---------------- |
333 |
||
334 |
Pulling from repo: |
|
335 |
~~~~~~~~~~~~~~~~~~ |
|
336 |
||
96 | 337 |
As mentioned earlier that repositories in Mercurial are self-contained. This means that the changeset just created exists only in *letter* repository and not in previously cloned . There are a few ways that can be used to propagate this change into other repositories. *pull* command will download all changeset from main repo. :: |
26 | 338 |
|
96 | 339 |
$ cd letter-clone |
340 |
$ hg pull |
|
341 |
pulling from /home/baali/letter |
|
26 | 342 |
requesting all changes |
343 |
adding changesets |
|
344 |
adding manifests |
|
345 |
adding file changes |
|
346 |
added 2 changesets with 2 changes to 2 files |
|
347 |
(run 'hg update' to get a working copy) |
|
348 |
||
349 |
*changeset* means a list of changes made to a file. In words of *hg help*, pull command is: :: |
|
350 |
||
351 |
pull changes from the specified source |
|
352 |
||
96 | 353 |
Pull changes from a remote repository to a local one. |
26 | 354 |
|
96 | 355 |
This finds all changes from the repository at the specified path |
356 |
or URL and adds them to the local repository. By default, this |
|
357 |
does not update the copy of the project in the working directory. |
|
26 | 358 |
|
359 |
Some times, even before pulling changesets, one may need to see what changes would be pulled, Mercurial provides *hg incoming* to tell what changes *hg pull* would pull into repo, without actually pulling the changes. This command is really handy in case of avoiding unwanted changesets into the repo. |
|
360 |
||
96 | 361 |
As output of *pull* command suggests it does not(by default) update the working directory. By update we mean, content of files and directory structure still remains the same as prior to *pull* command. *hg up (alias update)* command updates repo by adding latest imported changesets and bringing it upto date. :: |
26 | 362 |
|
96 | 363 |
$ ls -a |
364 |
. .. .hg |
|
365 |
$ hg up |
|
366 |
2 files updated, 0 files merged, |
|
367 |
0 files removed, 0 files unresolved |
|
368 |
$ ls -a |
|
369 |
. .. .hg letter-personal.tex |
|
370 |
letter-pro.tex |
|
26 | 371 |
|
96 | 372 |
To update to specific version, give a version number to the *hg update* command. |
26 | 373 |
|
374 |
Making Changes: |
|
375 |
~~~~~~~~~~~~~~~ |
|
376 |
||
96 | 377 |
Lets start with adding content to letters. For start personal letter can be a letter to ask a boy/girl out! Using LaTeX to write letter, it would be straight forward, open the file in any text editor and add the following content to it :: |
26 | 378 |
|
96 | 379 |
\documentclass{letter} |
380 |
\begin{document} |
|
381 |
\begin{letter}{} |
|
382 |
\opening{Hello xxxxxx,} |
|
383 |
I really enjoyed meeting you in CS 101, |
|
384 |
but would love to know you better. |
|
385 |
How about a coffee on Thursday after class? |
|
386 |
\closing{-xxxxx} |
|
387 |
\end{letter} |
|
388 |
\end{document} |
|
26 | 389 |
|
96 | 390 |
Replace "xxxxx" with proper names to suite yourself. Mercurial's hg status command will tell us what Mercurial knows about the files in the repository. 'M' sign in front of feviStick.py indicates that Mercurial has noticed change(modified). :: |
26 | 391 |
|
96 | 392 |
$ hg st |
393 |
M letter-personal.tex |
|
394 |
||
395 |
At times more information is needed on knowing exactly what changes were made to what files. To do this, use the *hg diff* command. :: |
|
26 | 396 |
|
397 |
$ hg diff |
|
96 | 398 |
diff -r 4a2d973a92de letter-personal.tex |
399 |
--- a/letter-personal.tex Tue Feb 23 19:50:39 2010 +0530 |
|
400 |
+++ b/letter-personal.tex Tue Jun 08 16:12:19 2010 +0530 |
|
401 |
@@ -0,0 +1,11 @@ |
|
402 |
+\documentclass{letter} |
|
403 |
+\begin{document} |
|
404 |
+ |
|
405 |
+\begin{letter}{} |
|
406 |
+\opening{Hello Jas,} |
|
407 |
+ |
|
408 |
+I really enjoyed meeting you in CS 101, but would love to know you better. How about a coffee on Thursday after class? |
|
409 |
+ |
|
410 |
+\closing{-Samarth} |
|
411 |
+\end{letter} |
|
412 |
+\end{document} |
|
413 |
||
414 |
We can modify files, build and test our changes, and use hg status and hg diff to review our changes, until we're satisfied with what we've done and arrive at a natural stopping point where we want to record our work in a new changeset. All the diffs prior to committing the changes would be done wrt earlier marked record.Then we use *hg commit* to create a new changeset |
|
26 | 415 |
|
96 | 416 |
Mercurial records your name and email-address with each change that you commit, so that you and others will later be able to tell who made each change. It also tries to automatically figure out a sensible username to commit the change with. When we try to use *hg commit* there are various ways by which one can specify User name, some of those are: |
417 |
||
418 |
- Specify a -u option to the hg commit command on the command line, followed by a username, this is the procedure we used earlier. |
|
419 |
- set HGUSER environment variable:: |
|
26 | 420 |
|
96 | 421 |
$ export HGUSER="xxxxx" |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
422 |
- Edit hgrc file present in .hg folder to set this property, add following lines to that file and Mercurial will read those parameters from that location. :: |
26 | 423 |
|
424 |
[ui] |
|
425 |
username = Firstname Lastname <email.address@example.net> |
|
426 |
||
96 | 427 |
For me the hgrc file for *letter* clone repo looks like this: :: |
26 | 428 |
|
96 | 429 |
[paths] |
430 |
default = /home/baali/letter |
|
431 |
[ui] |
|
432 |
username = Shantanu Choudhary <shantanu@fossee.in> |
|
26 | 433 |
|
434 |
Once this parameter is set, *hg commit* command drops us into a text editor, to enter a message that will describe the modifications we've made in this changeset. This is called the commit message. It will be a record for readers of what we did and why, and it will be printed by hg log after we've finished committing. :: |
|
435 |
||
96 | 436 |
Added content to personal letter. |
26 | 437 |
HG: Enter commit message. Lines beginning with 'HG:' are removed. |
438 |
HG: -- |
|
439 |
HG: user: Shantanu Choudhary <shantanu@fossee.in> |
|
440 |
HG: branch 'default' |
|
96 | 441 |
HG: changed letter-personal.tex |
26 | 442 |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
443 |
This would be your default system editor(for me it is vim, one can set it also), where you can enter the log message in first line, once you are done with log message quit the editor using *[ESC] key ":wq"*.Once we've finished the commit, we can use the hg tip command to display the changeset we just created. :: |
26 | 444 |
|
445 |
$ hg tip |
|
96 | 446 |
changeset: 2:a5d8cb2fac01 |
447 |
user: Shantanu <shantanu@fossee.in> |
|
448 |
date: Tue Feb 23 20:34:12 2010 +0530 |
|
449 |
summary: Added content to personal letter. |
|
450 |
||
26 | 451 |
One can do above mentioned procedure using following one line command: :: |
452 |
||
96 | 453 |
$ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Added content to personal letter." |
26 | 454 |
|
455 |
Sharing Changes: |
|
17
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
456 |
~~~~~~~~~~~~~~~~ |
e6240ecd7ae6
Basic file management in Repo.
Shantanu <shantanu@fossee.in>
parents:
16
diff
changeset
|
457 |
|
96 | 458 |
So now we have this *letter-clone* repo where we created above changes and committed them. But the main repo(*trunk*) that is *letter* wont be hinted of these changes. It will be still in older stage, same way as we pulled changes to this cloned repo from main branch at starting. To share changes from a cloned repo to main branch hg provides with *push* command. It is same as *pull* but instead of pulling it pushes the changes to trunk. :: |
26 | 459 |
|
460 |
$ hg push ../Fevicol |
|
461 |
pushing to ../Fevicol |
|
462 |
searching for changes |
|
463 |
adding changesets |
|
464 |
adding manifests |
|
465 |
adding file changes |
|
466 |
added 1 changesets with 1 changes to 1 files |
|
467 |
||
96 | 468 |
Same as with hg pull, the hg push command populates the changesets nothing more. :: |
26 | 469 |
|
96 | 470 |
$ cd ../letter |
26 | 471 |
$ hg tip |
96 | 472 |
changeset: 2:a5d8cb2fac01 |
473 |
user: Shantanu <shantanu@fossee.in> |
|
474 |
date: Tue Feb 23 20:34:12 2010 +0530 |
|
475 |
summary: Added content to personal letter. |
|
476 |
||
477 |
The branch where changes are being pushed still need *up* to be updated or for inclusion of all the imported changesets :: |
|
26 | 478 |
|
96 | 479 |
$ hg up |
26 | 480 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
96 | 481 |
$ cat letter-personal.tex |
482 |
\documentclass{letter} |
|
483 |
\begin{document} |
|
484 |
\begin{letter}{} |
|
485 |
\opening{Hello xxxx,} |
|
486 |
I really enjoyed meeting you in CS 101, but would love to know you better. How about a coffee on Thursday after class? |
|
487 |
||
488 |
\closing{-xxxx} |
|
489 |
\end{letter} |
|
490 |
\end{document} |
|
26 | 491 |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
492 |
Merging the Work: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
493 |
~~~~~~~~~~~~~~~~~ |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
494 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
495 |
This is next aspect of any version control, how to merge work done by various participants of project in a way that no one looses changes being made, and still remains updated. Here is simple case study which can help understanding why merging is required: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
496 |
|
38 | 497 |
Two persons, A and B are contributing on same project. Both starts from cloning the same online repo(lets say present state X), so that both have a working local repo. Now A edits one of file, commits the changes and pushes to the repo, hence changing the state of repo to Y, but B, have not updated his repo, makes a change in one of files and reaches to a different state Z. Now when A pulls repo from B, his repo will have multiple heads. This stage is clearly ambiguous, the repo of A is not consistent, it has multiple heads, and from here, whatever changes he makes can take whatsoever direction if it is not fixed, and hence A will have to merge changes so that everything becomes consistent again. |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
498 |
|
96 | 499 |
Lets see how this work with working repo, we will use letter and letter-clone repositories created earlier. For now, the status of both repo is: :: |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
500 |
|
96 | 501 |
$ cd letter-clone |
502 |
$ hg tip |
|
503 |
changeset: 2:a5d8cb2fac01 |
|
504 |
user: Shantanu <shantanu@fossee.in> |
|
505 |
date: Tue Feb 23 20:34:12 2010 +0530 |
|
506 |
summary: Added content to personal letter. |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
507 |
|
96 | 508 |
We share(clones) this repo with a friend, he goes through the letter and just makes small change of adding color to clogins part of letter. :: |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
509 |
|
96 | 510 |
$ hg diff |
511 |
diff -r 4a2d973a92de letter-personal.tex |
|
512 |
--- a/letter-personal.tex Tue Feb 23 19:50:39 2010 +0530 |
|
513 |
+++ b/letter-personal.tex Wed Feb 24 12:03:33 2010 +0530 |
|
514 |
@@ -0,0 +1,12 @@ |
|
515 |
\documentclass{letter} |
|
516 |
+\usepackage{color} |
|
517 |
\begin{document} |
|
518 |
. |
|
519 |
-\closing{-Samarth} |
|
520 |
+\closing{\textcolor{red}{-Samarth}} |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
521 |
|
96 | 522 |
Here the "-" sign shows which lines are removed, and "+" indicates what lines are added. He is satisfied and commits the changes. :: |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
523 |
|
96 | 524 |
$ hg ci -u "Vattam <vattam@fossee.in>" -m "Added some suggestions." |
525 |
changeset: 3:71fd776d856b |
|
526 |
parent: 2:a5d8cb2fac01 |
|
527 |
user: Vattam <vattam@fossee.in> |
|
528 |
date: Wed Feb 24 12:54:31 2010 +0530 |
|
529 |
summary: Added some suggestions. |
|
530 |
||
531 |
In the meanwhile, it seems, our "xxxx" is already dating someone else. So we also change the name to "yyyy" who is available, and we commit it :: |
|
532 |
||
533 |
$ cd letter |
|
534 |
$ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Changed name." |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
535 |
$ hg tip |
96 | 536 |
changeset: 3:02b49a53063f |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
537 |
user: Shantanu <shantanu@fossee.in> |
96 | 538 |
date: Wed Feb 24 13:12:26 2010 +0530 |
539 |
summary: Changed name. |
|
540 |
||
541 |
So now we have two repo, who have different commit history and tree. |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
542 |
|
96 | 543 |
.. image:: glog-main.png |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
544 |
|
96 | 545 |
.. image:: glog-suggestion.png |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
546 |
|
96 | 547 |
If we try to pull changes from one to another, this is how it goes(we are still in letter repo): :: |
548 |
||
549 |
$ hg pull ../letter-suggestion |
|
550 |
pulling from ../letter-suggestion |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
551 |
searching for changes |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
552 |
adding changesets |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
553 |
adding manifests |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
554 |
adding file changes |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
555 |
added 1 changesets with 1 changes to 1 files (+1 heads) |
96 | 556 |
(run 'hg heads' to see heads, 'hg merge' to merge) |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
557 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
558 |
There we go, since both repo were on different track, hg pull command in last line gives some heading from here. *hg heads* command show current repository heads or show branch heads. :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
559 |
|
96 | 560 |
$ hg heads |
561 |
changeset: 4:71fd776d856b |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
562 |
tag: tip |
96 | 563 |
parent: 2:a5d8cb2fac01 |
564 |
user: Vattam <vattam@fossee.in> |
|
565 |
date: Wed Feb 24 12:54:31 2010 +0530 |
|
566 |
summary: Added some suggestions. |
|
567 |
||
568 |
changeset: 3:02b49a53063f |
|
569 |
user: Shantanu <Shantanu@fossee.in> |
|
570 |
date: Wed Feb 24 13:12:26 2010 +0530 |
|
571 |
summary: Changed name. |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
572 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
573 |
To get better understanding of what is going on hg have a tool known as *glog* which shows revision history alongside an ASCII revision graph. :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
574 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
575 |
$ hg glog |
96 | 576 |
|
577 |
.. image:: heads.png |
|
26 | 578 |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
579 |
To bring repo on single track/branch once again we will have to merge these two branches. Without merging them even hg update wont work for obvious reason of confusing track record. :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
580 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
581 |
$ hg up |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
582 |
abort: crosses branches (use 'hg merge' or 'hg update -C') |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
583 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
584 |
*hg merge* command merge working directory with another revision. :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
585 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
586 |
$ hg merge |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
587 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
96 | 588 |
(branch merge, don't forget to commit) |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
589 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
590 |
After merging two branches, until we commit the results of merge it will keep on showing two heads. :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
591 |
|
96 | 592 |
$ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Merged branches." |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
593 |
$ hg glog |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
594 |
|
96 | 595 |
.. image:: glog-2.png |
596 |
||
597 |
*And we are back on track.* |
|
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
598 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
599 |
Workflow: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
600 |
========= |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
601 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
602 |
This is chain of steps which can be followed for working against a project that has a centralized copy, you may want to make sure you're up to date first. This means pulling its changes and then updating. |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
603 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
604 |
For example: :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
605 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
606 |
$ hg pull |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
607 |
$ hg update |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
608 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
609 |
This will grab the remote changes from the location you first cloned from. Then it will apply the changes. You can do this in one go with: :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
610 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
611 |
$ hg pull -u |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
612 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
613 |
Now let's say you make some changes. You edit a file and you want to commit your change. You can do this with: :: |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
614 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
615 |
$ hg commit |
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
616 |
|
54
bed3fe467e21
First version of 5-6 Session of ult.
Shantanu <shantanu@fossee.in>
parents:
38
diff
changeset
|
617 |
An editor will pop-up asking you to write a message describing your change. When you're done for the day, and you have required changesets sitting in your repository. Before pushing to upstream make sure to pull and update and merge branches if required, once everything looks okay and you have single track, push the changes, :: |
37
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
618 |
|
4cddf3a13843
Added merging section, and typo correction.
Shantanu <shantanu@fossee.in>
parents:
26
diff
changeset
|
619 |
$ hg push |
16
7a8f9fa7accd
Completed Getting Started with Repository.
Shantanu <shantanu@fossee.in>
parents:
15
diff
changeset
|
620 |
|
96 | 621 |
Cheatsheet |
622 |
========== |
|
623 |
||
624 |
.. image:: mod.png |
|
625 |
||
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
626 |
Suggested Reading: |
26 | 627 |
================== |
8
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
628 |
|
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
629 |
* http://karlagius.com/2009/01/09/version-control-for-the-masses/ |
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
630 |
* http://betterexplained.com/articles/a-visual-guide-to-version-control/ |
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
631 |
* http://en.wikipedia.org/wiki/Revision_control |
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
632 |
* http://hgbook.red-bean.com/ |
461e2574d624
Added CVCS and DVCS subsection.
Shantanu <shantanu@fossee.in>
parents:
7
diff
changeset
|
633 |
* http://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/ |
38 | 634 |
* http://wiki.alliedmods.net/Mercurial_Tutorial |