วันพฤหัสบดีที่ 3 กันยายน พ.ศ. 2558

Version control systems (Mercurial)

Version control systems Mercurial

 Getting started with mercurial on Ubuntu

What is mercurial??
Mercurial จัดเป็นโปรแกรมในประเภท control version โดยโปรแกรมจะสามารถเก็บ source code ที่เรานั้นเขียนเก็บเป็นแต่ละ  version สามารถดูการเปลี่ยนแปลงของในแต่ละ version กรณีที่งานเกิดหายสามารถ clone กลับมาใช้ใหม่ได้(แต่ต้อง push repository ไว้ในเวปที่ให้บริการเก็บ
เช่น www.github.com และ www.bitbucket.org‎) สามารถย้อนกลับ version ที่เคยทำมาก่อนหน้า สามารถดูว่าใครบันทึกหรือแก้ไขโค๊ดส่วนไหน 

How to install mercurial on ubuntu?
เราสามารถพิมพ์ Command เพื่อติดตั้งง่ายๆ ได้ด้วยคำสั่ง
 sudo apt-get install mercurial  
และ version ที่ติดตั้งได้ด้วย Command
 hg --version  


Start mercurial!!

ก่อนอื่นต้องสร้างหรือเลือก Folder ที่จะนำมาทำเป็น Repository ในที่นี้จะทำการเลือก Folder เป็น /home/nazari/Desktop/work/w4-2/Djangotutorial จากนั้นพิมพ์ Command hg init เพื่อเป็นการสร้าง Repository
 hg init  

ต่อไปจะเป็นการเช็คสถานะภายใน Directory ที่ทำงานอยู่ว่ามีการเปลี่ยนอะไรหรือไหม สถานะแต่ละไฟล์เป็นอย่างไร โดยใช้ Command hg status
 hg status  
สัญลักษณ์หน้าไฟล์แต่ละไฟล์จะมีความหมายที่แตกต่างกัน เช่น M หมายถึง มีการ modify เป็นต้น โดยจะแสดงดังตามด้านล่างนี้
M modified
A added
R removed
C clean
! missing
? not tracked
I ignored

ต่อไปจะเป็นการ add ไฟล์ manage.py เข้าไป repository เพื่อที่จะเพิ่มไฟล์เข้าไปในการ commit ครั้งต่อไป โดยจะใช้ Command
 hg add [file/folder] 

หลังจากเราทำการ add ไฟล์แล้วพิมพ์ hg status ดูอีกครั้งจะพบว่าสถานะหน้าไฟล์ของ manage.py มีสถานะเปลี่ยนแปลงไป

เมื่อทำการ add ไฟล์หรือแก้ไขไฟล์ต่างๆ เรียบร้อยแล้ว ต่อไปจะเป็นการสร้าง version(changeset) ของ repository ภายในโฟลเดอร์นี้เราจะใช้ Command hg commit [OPTION]... [FILE]... ซึ่ง options ต่างๆเราสามารถดูได้จากตารางด้านล่าง ปกติแล้วเราจะใช้เพียงแค่ option -m และ -u เท่านั้น
 hg commit [OPTION]... [FILE]...  

OPTIONS
-A --addremove mark new/missing files as added/removed before committing
--close-branch mark a branch as closed, hiding it from the branch list
--amend amend the parent of the working dir
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
-m --message TEXT use text as commit message
-l --logfile FILE read commit message from file
-d --date DATE record the specified date as commit date
-u --user USER record the specified user as committer
-S --subrepos recurse into subrepositories

ถ้าเราอยากจะรู้ว่าที่เราทำใน Repository นั้นได้มี version อะไรที่เคยทำผ่านมา มีจำนวน version เท่าไหร่  เราจะใช้ Command hg log 
 hg log  

เมื่อเราต้องการที่จะรู้ว่ามีการ เปลี่ยนแปลงอะไรไปบ้างภายในไฟล์ต่างๆ ที่ได้ทำแก้ไขหรือเพิ่มเติมเข้ามาเราสามารถใช้ Command hg diff [file]
 hg diff [FILE]...  

(+)ข้่างหน้าคือสิ่งที่เพิ่มเข้ามา (-)คือส่วนที่เอาออกไป

ใน บางครั้ง ก็มักจะไฟล์บางอย่างที่เราไม่ต้องการที่จะเพิ่มเข้าใน Repository ของเรา อย่างเช่น ในการ run server manage.py จะมีไฟล์ .pyc สร้างขึ้นมาเสมอ เราสามารถทำให้ mercurial ไม่สนใจไฟล์ชนิดได้ โดยเราต้องสร้างไฟล์ .hgignore ขึ้นมาโดยจะพิมพ์ syntax ตามรูปแบบด้านล่าง จากนั้นให้ทำการ add ไฟล์ .hgignore เข้าไปใน Repository ไฟล์ .pyc ก็จะไม่ขึ้นใน Repository นี้อีก
 # use glob syntax.  
 syntax: glob  
 *.elc  
 *.pyc  
 *~  
 # switch to regexp syntax.  
 syntax: regexp  
ไฟล์ .pyc หลังจาก run server
ทำการสร้างไฟล์ .hgignore และทำการ  add ใน Repository

ตรวจสอบด้วยการพิมพ์คำสั่ง $hg status จะเห็นว่าไม่ไฟล์ .pyc

Mercurial นั้นสามารถที่จะให้ผู้ใช้งานดูรายละเอียดเกี่ยว กับ Repository และยังดูวิธีการใช้คำสั่งต่างๆ ผ่าน GUI โดยเรียกใช้ผ่าน browser เพียงพิมพ์ Command $hg serve เท่านี้ จากนั้นให้ไปที่ 127.0.0.1:8000 
 hg serve  




อ้างอิงจาก : https://www.selenic.com/mercurial/hg.1.html

ไม่มีความคิดเห็น:

แสดงความคิดเห็น