DGPLUG Training Topic – Mercurial

What is Mercurial?

1. It is a open source, cross platform, distributed revision control tool.

2. It is implemented using Python.

3. It is a command-line program. It also supports GUI (Graphical User Interface) extentions.

How to install Mercurial on Linux (Fedora)?

1. Type the following command in the terminal to install Mercurial on Fedora:
sudo yum install mercurial

2. To check if Mercurial is correctly installed in your system, type the following command in the terminal:
hg

3. To check what version of Mercurial is installed in your system, type the following command in the terminal:
hg version

4. To get help on commands, type the following command in the terminal:
hg help

Step 1: Configure Mercurial

1. In your home directory, create a text file named “.hgrc”.
Path should be: ~/.hgrc
Now, write the following text replacing
– <first_name> with your first name e.g. Peter
– <last_name> with your last name e.g. Wilson
– <your_email_id> with your email id e.g. peter.xyz123@gmail.com

[ui]
username = <first_name> <last_name> <your_email_id>

[extensions]
purge =
strip =
color =
pager =
progress =
rebase =

[pager]
pager = LESS=’FSRX’ less
attend = tags, help, annotate, cat, diff, export, status,\
outgoing, incoming, glog, log, grep

2. This username is required during configuration for recording commits.

Step 2: Initialize a repository

1. Repository is a place where data is stored and maintained. Create a repository by typing the following command in the terminal:
mkdir <project_name>

Enter inside your directory by typing the following command in the terminal:
cd <project_name>

2. Initialize the repository by typing the following command in the terminal:
hg init <project_name>

3. Initializing a repository means putting the repository in the condition appropriate to the start of an operation.

4. After initializing you will find “.hg” directory in your new repository. To check, type the following command in the terminal:
ls -la

Step 3: Add files

1. Create a file inside your repository <project_name>. Here, we will create a python source code file: file1.txt. To create this file, type the following in the termial:
touch file1.txt

Now write some statements in the file and then save it.

2. To add a specific file to mercurial i.e place the files under version control; type following command in the terminal:
hg add file1.txt

3. To add more than one file to mercurial, type following command in the terminal:
hg add <file1> <file2> <file3>

4. To add all the files to mercurial, type the following command in the terminal:
hg add

5. Adding a file means that you are specifying the files you want to track. These files are not “in” Mercurial yet.

Step 4: Track files

1. To permanently save the file and track the files using the following command in the terminal:
hg commit -m “<commit_message>”

2. Files are now permanently stored in the repository.

3. To open an editor which displays all Mercurial commits, type the following command in the terminal:
hg commit

Step 5: Check the history

1. Look into your history, type the following command in the terminal:
hg log

Step 6: Check changes

1. To see which files changed, added, removed, tracked or are not tracked; type the following command in your terminal:
hg status

Step 7: See exact changes

1. To see exact changes in your files, type the following command in the terminal:
hg diff

Advertisements
DGPLUG Training Topic – Mercurial

DGPLUG Training Topic – Revision Control Tool

What is revision control tool?

1. Revision control/ version control/ source control is used to manage changes to documents, computer programs or any such collection of information.

2. The document could be as simple as a text file, programming language codes or collection of many files and documents.

Why do we need revision control tool?

1. It is useful for projects where multiple people work on the same project.

2. When you mess up, you can easily get back to previous working version.

3. To avoid general chaos while working on large software projects.

4. To track ownership with the name of person who made it.

What is a basic revision control tool setup made up of?

1. Repository (Repo) – database to store files

2. Server – computer which stores the repo

3. Client – computer connecting to the repo

4. Working copy – local directory of files where you make changes

5. Main – primary location for code in repo

What is distributed version control tool?

1. Simple revision control only allows us to backup, track and synchronize files. Distributed version control tool makes it easy to share changes.

2. In distributed model, every developer has their own repo.

3. Distributed systems have no specific structure. We can have either:

– centrally administered structure

– everybody as peers

Examples of revision control tools?

1. Mercurial

2. Git

 

DGPLUG Training Topic – Revision Control Tool

DGPLUG Training Topic – Vi/ Vim Text Editor

 

What is Vi?

Vi is a visual text editor. It is not a word processor.

Vi lets you add, change, and delete text, but does not provide such formatting capabilities as centering lines or indenting paragraphs.

What is vim?

1. Vim is VI iMproved.

2. It contains additional features than Vi.

3. It supports syntax highlighting and code folding for popular programming languages like Python and C.

4. It includes multi-level undo/redo.

5. It can be used to edit files using network protocols like SSH and HTTP.

6. It allows the screen to be split for editing multiple files.

7. It can edit files inside a compressed archive (gzip, zip, tar, etc).

8. It includes support for plugins, and finer control over config and startup files.

9. It can be scripted with vimscript, or with an external scripting language like python, perl, shell.

How to open a vi file?

Command to open a vi file with cursor in the first line:

$vi <filename>

Command to open a vi file with cursor in the last line:

$vi + <filename>

Command to open a vi file with cursor in n line:

$vi +n <filename>

where file could be of any extention.

If it is a new file, then it will be empty. If it is an old file, then it will show existing contents.

Modes of Vi

Command Mode :

Letters of keyboard we type perform editing functions. To enter command mode, press the escape <Esc> key.

Insert Mode :

Letters of keyboard we type form words and sentences.

Basic commands of vi

(! indicates negative form)

Press i

To type anything in the file.

Press a

To append (or enter) any text from current cursor position.

Type :w

To save the file.

Type :q

To exit if the file remains unchanged.

Type :q!

To exit without saving.

Type 😡 or :wq

To save and exit.

Type :e!

To not save and go back to last saved version.

Type :set nu

To set line number mode.

Type :set nu!

To remove line number mode.

Type :<linenumber>

To go to a particular line number.

Press r

To replace current character with a new one, press r, then new character.

Press x

To delete a character.

Press cw

To change a word.

Press C or c$

To end line at that cursor point and delete everything after that.

Press c0

To bring cursor to the beginning of line and delete everything in the line before it.

Press cc

To change a whole line.

Press d

To delete.

Press dw

To delete a word.

Press dd

To delete a line.

Press D or d$

To delete upto end of line.

Press d0

To delete upto beginning of line.

Press dd

To delete a line.

Press D or d$

To delete upto end of line.

Press d0

To delete upto beginning of line.

Press u

To undo.

Press Ctrl+r

To redo.

Press x

To cut a character.

Press y

To copy a character.

Press yw

To copy a word.

Press yy

To copy a line.

Press p

To paste.

Press ~

To change case of letter.

Press o

To add a new line below this line.

Press O

To add a new line above this line.

Press J

To join the current line and next line.

To move around in vi file

Press k

To move one char up.

Press j

To move on char down.

Press h

To move one char left.

Press l

To move one char right.

Press w

To move forward word by word.

Press b

To move backwards word by word.

Press o

To move to beginning of line.

Press $

To move to end of line.

Press c

To move to end of word.

Press G

To go to last line.

Press <linenumber>G

To go to a particular line.

Press Ctrl + F

To move forward one screen.

Press Ctrl + B

To move backwards one screen.

Press Ctrl + D

To move forward half screen.

Press Ctrl + U

To move backwards half screen.

Press +

To move to first character of next line.

Press –

To move to first character of last line.

Press e

To move to end of word.

To search a word in vi file

(Stay in the same line in which you want to search the word)

Type /searchword

To search any specific text in forward content.

Type ?searchword

To search any specific text in backwards content.

Press n/”/”

To go to next occurence.

Press N/?

To go to previous occurence.

Type :s/oldword/newword

To search a word and replace first occurence.

Type :s/oldword/newword/g

To search a word and replace all occurence in same line.

Type :l,$s/oldword/newword

To search a word and replace all occurence in all the lines.

Type :%s/oldstring/newstring/g

To search a word and replace all occurence in all the lines.

Type :%s/oldstring/newstring/gc

To search a word and replace all occurence in all the lines but confirming it first

 

DGPLUG Training Topic – Vi/ Vim Text Editor