Copy (2) of 3_version_control

Embed Size (px)

Citation preview

  • 8/2/2019 Copy (2) of 3_version_control

    1/42

  • 8/2/2019 Copy (2) of 3_version_control

    2/42

    Outline

    1 Introduction

    2 Let there be a Repo!

    3 But Why commit ?

    4 Collaborating with Mercurial

    5 Conclusion

    FOSSEE (IIT Bombay) Mercurial 2 / 42

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    3/42

    Objectives

    At the end of this session, you will be able to:

    Understand what is Version Control and the need

    for it

    Create and use repository on a daily basis

    Clone existing repositories, from the web

    View the history of a repository

    Make changes to a repository and commit themWork collaboratively with a team

    FOSSEE (IIT Bombay) Mercurial 3 / 42

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    4/42

    Introduction

    Outline

    1 Introduction

    2 Let there be a Repo!

    3 But Why commit ?

    4 Collaborating with Mercurial

    5 Conclusion

    FOSSEE (IIT Bombay) Mercurial 4 / 42

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    5/42

    Introduction

    What is Version Control?

    A way to track changes made to files over time, bykeeping copies of files as we change them.

    FOSSEE (IIT Bombay) Mercurial 5 / 42

    I d i

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    6/42

    Introduction

    Home-brewed

    An example of a home-brew Version Control system

    $ ls

    a.out id1.txt id2.txt identifier.cpp

    id.txt lex pda1.cpp pda2.cpp pda.cppFOSSEE (IIT Bombay) Mercurial 6 / 42

    I t d ti

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    7/42

    Introduction

    Problems

    Name and changes made are not related or linked.

    Cant track sequence of changes made to a file.

    Does not scale.

    FOSSEE (IIT Bombay) Mercurial 7 / 42

    Introduction

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    8/42

    Introduction

    The need for Version Control

    To err is Human . . .

    Tracking the history and evolution of a projectTo collaborate effectively on a project

    To efficiently track down bugs and pin-point the

    changes that caused it

    FOSSEE (IIT Bombay) Mercurial 8 / 42

    Introduction

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    9/42

    Introduction

    How does it work? Analogy

    It is, in some ways, similar to playing an Video game.

    We play games in stages

    Once we finish a stage or a task we SAVEWe continue playing

    But, if necessary, we could choose from one of the

    saved states and start from there

    We could alter the course of the game

    FOSSEE (IIT Bombay) Mercurial 9 / 42

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    10/42

    Introduction

  • 8/2/2019 Copy (2) of 3_version_control

    11/42

    Introduction

    Installation

    sudo apt-get install mercurial

    TortoiseHg$ hg

    $ hg version

    FOSSEE (IIT Bombay) Mercurial 11 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    12/42

    p

    Outline

    1 Introduction

    2 Let there be a Repo!

    3 But Why commit ?

    4 Collaborating with Mercurial

    5 Conclusion

    FOSSEE (IIT Bombay) Mercurial 12 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    13/42

    p

    We need a repo!

    A Repository (repo) is where all the action is!

    Project files along with a special directory thatstores all the changes

    We take snapshots of the whole repository; not

    individual files.

    FOSSEE (IIT Bombay) Mercurial 13 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    14/42

    Initializing a repo

    $ hg init

    Creates a fresh repositoryAdds a .hg directory to our working directory

    .hg directory keeps log of changes made henceforth

    FOSSEE (IIT Bombay) Mercurial 14 / 42

    Let there be a Repo!

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    15/42

    Status report

    hg status gives the status of our repo

    Use it often; at least as a beginnerhg help command gives us help about

    command

    FOSSEE (IIT Bombay) Mercurial 15 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    16/42

    Status codes

    M = modified

    A = added

    R = removedC = clean

    ! = missing

    ? = not tracked

    I = ignored

    FOSSEE (IIT Bombay) Mercurial 16 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    17/42

    Adding files

    From hg status we know, none of the files are

    being tracked, yet.

    hg add asking hg to track these filesAs expected hg status prepends an A to the file

    names.

    ? - - > A

    ! - - > R (hg remove)

    FOSSEE (IIT Bombay) Mercurial 17 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    18/42

    Taking Snapshots

    hg commit

    Asking Mercurial to take a snapshot; remember

    the changes made to the repository.

    -u FirstName LastName

    -m Commit message a description of

    changes committed.

    FOSSEE (IIT Bombay) Mercurial 18 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    19/42

    Thumbnail views

    hg log gives the log of the changes made

    A changeset is an atomic collection of changes

    to the files (between successive commits)

    Log information

    changeset: Identifier for the changeset

    user: Details of user who created the changeset

    date: Date and time of creation

    summary: One line description

    FOSSEE (IIT Bombay) Mercurial 19 / 42

    Let there be a Repo!

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    20/42

    User information

    User information is set in the hgrc file

    It can be set globally or local to the projectGlobal hgrc

    $HOME/.hgrc Unix like systems

    %HOME%\.hgrc Windows

    FOSSEE (IIT Bombay) Mercurial 20 / 42

    Let there be a Repo!

    Ad i

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    21/42

    Advice: commits, messages

    Atomic changes; one change with one commit

    Single line summary 60 to 65 characters long

    Followed by paragraphs of detailed descriptionWhy the change?

    What does it effect?

    Known bugs/issues?

    etc.

    FOSSEE (IIT Bombay) Mercurial 21 / 42

    But Why commit ?

    O tli

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    22/42

    Outline

    1 Introduction

    2 Let there be a Repo!

    3 But Why commit ?

    4 Collaborating with Mercurial

    5 Conclusion

    FOSSEE (IIT Bombay) Mercurial 22 / 42

    But Why commit ?

    O ti l h d?

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    23/42

    Operational overhead?

    But why do we commit?

    Isnt all this just adding to operational costs?

    Isnt all this a waste of time?

    No! You shall see the benefits, soon!

    FOSSEE (IIT Bombay) Mercurial 23 / 42

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    24/42

    But Why commit ?

    Vi i Ch

  • 8/2/2019 Copy (2) of 3_version_control

    25/42

    Viewing Changes

    hg diff all changes since last commit

    - this line was deleted

    + this line was added

    FOSSEE (IIT Bombay) Mercurial 25 / 42

    But Why commit ?

    Re ision n mbering

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    26/42

    Revision numbering

    changeset: n:cbf6e2a375b4

    n is the revision numberThe revision number is local to a repository

    cbf6e2a375b4 is the unique identifier

    FOSSEE (IIT Bombay) Mercurial 26 / 42

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    27/42

    Collaborating with Mercurial

    Outline

  • 8/2/2019 Copy (2) of 3_version_control

    28/42

    Outline

    1 Introduction

    2 Let there be a Repo!

    3 But Why commit ?

    4 Collaborating with Mercurial

    5 Conclusion

    FOSSEE (IIT Bombay) Mercurial 28 / 42

    Collaborating with Mercurial

    Cloning Repositories

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    29/42

    Cloning Repositories

    hg clone SOURCE [DEST]All hg repositories are self-contained

    FOSSEE (IIT Bombay) Mercurial 29 / 42

    Collaborating with Mercurial

    Sharing Repositories

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    30/42

    Sharing Repositories

    hg serveCan be cloned with

    hg clone http://my-ip-address:8000

    We share a central repository; work on our localcopies.

    Set write permissions in .hg/hgrc

    [web]push_ssl=False

    allow_push=*

    FOSSEE (IIT Bombay) Mercurial 30 / 42

    Collaborating with Mercurial

    Sharing Changes

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    31/42

    Sharing Changes

    Use hg push to push your commits(changesets) to the central repository

    FOSSEE (IIT Bombay) Mercurial 31 / 42

    Collaborating with Mercurial

    Pulling Changes

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    32/42

    Pulling Changes

    hg incoming shows new changesets in the

    server

    To get these changesets, we use hg pullThese changes do not affect our working directory

    hg parent shows the parents of the working

    directory

    FOSSEE (IIT Bombay) Mercurial 32 / 42

    Collaborating with Mercurial

    Pulling Changes

    http://find/
  • 8/2/2019 Copy (2) of 3_version_control

    33/42

    Pulling Changes . . .

    hg update will update the working directoryUpdates to the tip if no revision is specified

    tip is the most recently added changesetCan specify revision number to update to

    hg tip shows the tip of the repository

    FOSSEE (IIT Bombay) Mercurial 33 / 42

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    34/42

    Collaborating with Mercurial

    Merging

  • 8/2/2019 Copy (2) of 3_version_control

    35/42

    Merging

    Pull and merge, when

    abort: push creates new remote heads!hg merge will merge the two diverged heads

    commit after you have merged!

    FOSSEE (IIT Bombay) Mercurial 35 / 42

    Collaborating with Mercurial

    Simultaneous Changes

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    36/42

    Simultaneous Changes . . .

    outgoing shows the changesets that will be

    pushedhg push works!

    Look at the Change graph!

    FOSSEE (IIT Bombay) Mercurial 36 / 42

    Collaborating with Mercurial

    Simultaneous Conflicting Changes

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    37/42

    Simultaneous Conflicting Changes

    What if the changes conflict? overlapping edits

    hg push fails; hg pull; hg merge

    You now get a diff view with 3 panes

    First current fileSecond changesets that you pulled

    Third file before you made your changes

    Resolve conflict and save

    hg commit; hg pushLook at the Change graph!

    FOSSEE (IIT Bombay) Mercurial 37 / 42

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    38/42

  • 8/2/2019 Copy (2) of 3_version_control

    39/42

    Conclusion

    Summary I

  • 8/2/2019 Copy (2) of 3_version_control

    40/42

    Summary I

    In this session, we have learnt to:

    initialize new repositories, using hg init

    check the status using hg status

    get help for any command using hg help

    commit changes or take snapshots using

    hg commit

    view the history of a repository using hg log

    set the user info in the global hgrc fileundo changes using hg revert

    view changes using hg diff

    FOSSEE (IIT Bombay) Mercurial 40 / 42

    Conclusion

    Summary II

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    41/42

    Summary II

    use revision numbers as arguments to various

    commands

    clone repositories using hg clone

    server repositories using hg serve

    push changes using hg pushpull changes using hg pull

    update working directory to latest revision using

    hg updatemerge two heads using hg merge

    resolve merge conflicts using hg resolve

    FOSSEE (IIT Bombay) Mercurial 41 / 42

    Conclusion

    References

    http://find/http://goback/
  • 8/2/2019 Copy (2) of 3_version_control

    42/42

    A Visual Guide to Version Control

    Version Control for the Masses

    (Illustrated) Intro to Distributed Version Control

    Understanding Mercurial

    A Tutorial on Using Mercurial

    Hg Init: a Mercurial tutorial

    Beginners GuidesSoftware Carpentry

    FOSSEE (IIT Bombay) Mercurial 42 / 42

    http://betterexplained.com/articles/a-visual-guide-to-version-control/http://karlagius.com/2009/01/09/version-control-for-the-masses/http://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/http://mercurial.selenic.com/wiki/UnderstandingMercurialhttp://mercurial.selenic.com/wiki/Tutorialhttp://hginit.com/http://mercurial.selenic.com/wiki/BeginnersGuideshttp://software-carpentry.org/4_0/vc/http://software-carpentry.org/4_0/vc/http://mercurial.selenic.com/wiki/BeginnersGuideshttp://hginit.com/http://mercurial.selenic.com/wiki/Tutorialhttp://mercurial.selenic.com/wiki/UnderstandingMercurialhttp://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/http://karlagius.com/2009/01/09/version-control-for-the-masses/http://betterexplained.com/articles/a-visual-guide-to-version-control/http://find/http://goback/