10 |
10 |
11 "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. |
11 "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. |
12 |
12 |
13 Version control (or source control) is nothing more arcane than keeping copies of ones work as one make changes to it. 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 off kilter. Accidentally deleted half of thesis and closed the word processor? No problem – out comes the backup." |
13 Version control (or source control) is nothing more arcane than keeping copies of ones work as one make changes to it. 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 off kilter. Accidentally deleted half of thesis and closed the word processor? No problem – out comes the backup." |
14 |
14 |
15 Now, in the real world, it’s not so easy. One probably cooks up their own version control system without realizing it had such a geeky name. For instances files with names oldxxxxxx.odt and latestxxxxxx.odt. 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. |
15 Now, in the real world, it’s not so easy. 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. |
16 |
16 |
17 Why Use Version Control |
17 Why Use Version Control |
18 ======================= |
18 ======================= |
19 |
19 |
20 "Its the start which most people fail to attempt". |
20 One of idea behind Version Control Tools was to build onto very first step which can be creating a empty file, or writting a first buggy program for assignment, rather then simply loose it. So here are some reasons why is automated version control needed: |
21 One of idea behind Version Control Tools was to save that "one" step, to build onto it, rather then simply loose it. So here are some reasons why is automated version control needed: |
|
22 |
21 |
23 - 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. |
22 - 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. |
24 - 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. |
23 - 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. |
25 - It can help to recover from mistakes. If a change made at some moment of time, turns out to be in 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. |
24 - It can help to recover from mistakes. If a change made at some moment of time, turns out to be in 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. |
26 |
25 |
501 $ hg up tip |
502 $ hg up tip |
502 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
503 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
503 $ $ cat feviStick.py |
504 $ $ cat feviStick.py |
504 print 'Ab no more Chip Chip' |
505 print 'Ab no more Chip Chip' |
505 |
506 |
506 Dos and Don'ts with Mercurial: |
507 Merging the Work: |
507 ============================== |
508 ~~~~~~~~~~~~~~~~~ |
508 |
509 |
509 |
510 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: |
|
511 |
|
512 Two persons, changu and mangu are contributing on same project. Both starts from cloning the same online repo(lets say present state A), so that both have a working local repo. Now changu edits one of file, commits the changes and pushes to the repo, hence changing the state of repo to B, but mangu, have not updated his repo, makes a change in one of files and reaches to a different state C. Now when changu pulls repo from mangu, his repo will have multiple heads. This stage is clearly ambiguous the repo of changu 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 changu will have to merge changes so that everything becomes consistent again. |
|
513 |
|
514 Lets see how this work with working repo, we will use Fevicol and Fevicol-clone repositories created earlier. For now, the status of both repo is: :: |
|
515 |
|
516 $ cd Fevicol-clone |
|
517 $ hg tip |
|
518 changeset: 3:e1ab2aff4ddd |
|
519 tag: tip |
|
520 user: Shantanu Choudhary <shantanu@fossee.in> |
|
521 date: Sun Aug 23 23:32:01 2009 +0530 |
|
522 summary: Changed tagline for feviStick.py. |
|
523 |
|
524 The tagline for feviCol.py is not complete, so we make changes in that file in this repo. :: |
|
525 |
|
526 $ echo "print 'Yeh Fevicol ka Majboot jod hai, tootega nahin'" > feviStick.py |
|
527 $ hg st |
|
528 M feviStick.py |
|
529 |
|
530 And commit the changes made :: |
|
531 |
|
532 $ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Updated tag line for feviCol.py." |
|
533 $ hg st |
|
534 $ hg tip |
|
535 changeset: 4:caf986b15e05 |
|
536 tag: tip |
|
537 user: Shantanu <shantanu@fossee.in> |
|
538 date: Tue Aug 25 16:28:24 2009 +0530 |
|
539 summary: Updated tag line for feviCol.py. |
|
540 |
|
541 Now we will make some changes on Fevicol repo. We will add new file here :: |
|
542 |
|
543 $ cd Fevicol |
|
544 $ echo "print 'Jor laga ke hayyiya'" > firstAdd.py |
|
545 $ hg st |
|
546 ? firstAdd.py |
|
547 $ hg add firstAdd.py |
|
548 $ hg st |
|
549 A firstAdd.py |
|
550 $ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Added firsAdd.py." |
|
551 $ hg tip |
|
552 changeset: 4:fadbd6492cc4 |
|
553 tag: tip |
|
554 user: Shantanu <shantanu@fossee.in> |
|
555 date: Tue Aug 25 16:46:24 2009 +0530 |
|
556 summary: Added firsAdd.py. |
|
557 |
|
558 So now we have two repo, who have different commit history and tree, now if we try to pull changes from one to another, this is how it goes(we are still in Fevicol repo): :: |
|
559 |
|
560 $ hg pull ../Fevicol-clone |
|
561 pulling from ../Fevicol-clone |
|
562 searching for changes |
|
563 adding changesets |
|
564 adding manifests |
|
565 adding file changes |
|
566 added 1 changesets with 1 changes to 1 files (+1 heads) |
|
567 (run 'hg heads' to see heads, 'hg merge' to merge) |
|
568 |
|
569 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. :: |
|
570 |
|
571 $ hg heads |
|
572 changeset: 5:caf986b15e05 |
|
573 tag: tip |
|
574 parent: 3:e1ab2aff4ddd |
|
575 user: Shantanu <shantanu@fossee.in> |
|
576 date: Tue Aug 25 16:28:24 2009 +0530 |
|
577 summary: Updated tag line for feviCol.py. |
|
578 |
|
579 changeset: 4:fadbd6492cc4 |
|
580 user: Shantanu <shantanu@fossee.in> |
|
581 date: Tue Aug 25 16:46:24 2009 +0530 |
|
582 summary: Added firsAdd.py. |
|
583 |
|
584 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. :: |
|
585 |
|
586 $ hg glog |
|
587 o changeset: 5:caf986b15e05 |
|
588 | tag: tip |
|
589 | parent: 3:e1ab2aff4ddd |
|
590 | user: Shantanu <shantanu@fossee.in> |
|
591 | date: Tue Aug 25 16:28:24 2009 +0530 |
|
592 | summary: Updated tag line for feviCol.py. |
|
593 | |
|
594 | @ changeset: 4:fadbd6492cc4 |
|
595 |/ user: Shantanu <shantanu@fossee.in> |
|
596 | date: Tue Aug 25 16:46:24 2009 +0530 |
|
597 | summary: Added firsAdd.py. |
|
598 | |
|
599 o changeset: 3:e1ab2aff4ddd |
|
600 | user: Shantanu Choudhary <shantanu@fossee.in> |
|
601 | date: Sun Aug 23 23:32:01 2009 +0530 |
|
602 | summary: Changed tagline for feviStick.py. |
|
603 | |
|
604 o changeset: 2:a7912d45f47c |
|
605 | user: Shantanu <shantanu@fossee.in> |
|
606 | date: Sun Aug 23 22:34:35 2009 +0530 |
|
607 | summary: Updated Content. |
|
608 | |
|
609 o changeset: 1:d948fb4137c5 |
|
610 | user: Shantanu <shantanu@fossee.in> |
|
611 | date: Sat Aug 22 00:11:25 2009 +0530 |
|
612 | summary: Renamed pidiLite.py. |
|
613 | |
|
614 o changeset: 0:84f5e91f4de1 |
|
615 user: Shantanu <shantanu@fossee.in> |
|
616 date: Fri Aug 21 23:37:13 2009 +0530 |
|
617 summary: First commit. |
|
618 |
|
619 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. :: |
|
620 |
|
621 $ hg up |
|
622 abort: crosses branches (use 'hg merge' or 'hg update -C') |
|
623 |
|
624 *hg merge* command merge working directory with another revision. :: |
|
625 |
|
626 $ hg merge |
|
627 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
628 (branch merge, don't forget to commit) |
|
629 $ hg tip |
|
630 changeset: 5:caf986b15e05 |
|
631 tag: tip |
|
632 parent: 3:e1ab2aff4ddd |
|
633 user: Shantanu <shantanu@fossee.in> |
|
634 date: Tue Aug 25 16:28:24 2009 +0530 |
|
635 summary: Updated tag line for feviCol.py. |
|
636 |
|
637 After merging two branches, until we commit the results of merge it will keep on showing two heads. :: |
|
638 |
|
639 $ hg ci -u "Shantanu <shantanu@fossee.in>" -m "Merged branches of add and tag line." |
|
640 $ hg heads |
|
641 changeset: 6:edbe97209954 |
|
642 tag: tip |
|
643 parent: 4:fadbd6492cc4 |
|
644 parent: 5:caf986b15e05 |
|
645 user: Shantanu <shantanu@fossee.in> |
|
646 date: Tue Aug 25 17:06:03 2009 +0530 |
|
647 summary: Merged branches of add and tag line. |
|
648 |
|
649 Here is brief and meaningful output of glog :: |
|
650 |
|
651 $ hg glog |
|
652 @ changeset: 6:edbe97209954 |
|
653 |\ tag: tip |
|
654 | | parent: 4:fadbd6492cc4 |
|
655 | | parent: 5:caf986b15e05 |
|
656 | | user: Shantanu <shantanu@fossee.in> |
|
657 | | date: Tue Aug 25 17:06:03 2009 +0530 |
|
658 | | summary: Merged branches of add and tag line. |
|
659 | | |
|
660 | o changeset: 5:caf986b15e05 |
|
661 | | parent: 3:e1ab2aff4ddd |
|
662 | | user: Shantanu <shantanu@fossee.in> |
|
663 | | date: Tue Aug 25 16:28:24 2009 +0530 |
|
664 | | summary: Updated tag line for feviCol.py. |
|
665 | | |
|
666 o | changeset: 4:fadbd6492cc4 |
|
667 |/ user: Shantanu <shantanu@fossee.in> |
|
668 | date: Tue Aug 25 16:46:24 2009 +0530 |
|
669 | summary: Added firsAdd.py. |
|
670 |
|
671 And we are back on track. |
|
672 |
|
673 Workflow: |
|
674 ========= |
|
675 |
|
676 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. |
|
677 |
|
678 For example: :: |
|
679 |
|
680 $ hg pull |
|
681 $ hg update |
|
682 |
|
683 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: :: |
|
684 |
|
685 $ hg pull -u |
|
686 |
|
687 Now let's say you make some changes. You edit a file and you want to commit your change. You can do this with: :: |
|
688 |
|
689 $ hg commit |
|
690 |
|
691 An editor will pop-up asking you to write a message describing your change. This is required. 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, :: |
|
692 |
|
693 $ hg push |
510 |
694 |
511 Suggested Reading: |
695 Suggested Reading: |
512 ================== |
696 ================== |
513 |
697 |
514 * http://karlagius.com/2009/01/09/version-control-for-the-masses/ |
698 * http://karlagius.com/2009/01/09/version-control-for-the-masses/ |