บรรทัดคำสั่ง Git
Feb 19 2023
ทั้งหมดเกี่ยวกับคำสั่ง git ระบบควบคุมเวอร์ชัน ช่วยให้นักพัฒนาทำงานร่วมกัน ทำงานพร้อมกัน รักษาประวัติของทุกเวอร์ชัน ประเภทของ VCS : CVCS : ระบบควบคุมเวอร์ชันแบบรวมศูนย์ DVCS : ระบบควบคุมเวอร์ชันแบบกระจาย Git Life Cycle การติดตั้ง Git Ubuntu sudo apt-get install git Windows ดาวน์โหลดจากลิงค์ด้านล่าง git --version Initialize git stash References
ทุกอย่างเกี่ยวกับคำสั่งคอมไพล์
ระบบควบคุมเวอร์ชัน
ช่วยให้นักพัฒนาทำงานร่วมกัน ทำงานพร้อมกัน รักษาประวัติของทุกเวอร์ชัน ประเภท
ของ VCS :
CVCS : ระบบควบคุมเวอร์ชันแบบรวมศูนย์
DVCS : ระบบควบคุมเวอร์ชันแบบกระจาย
Git วงจรชีวิต
การติดตั้ง Git
อูบุนตู
- แพ็คเกจ git มีให้ผ่าน apt
- ติดตั้งคอมไพล์โดยใช้ apt-get
sudo apt-get install git
หน้าต่าง
ดาวน์โหลดได้จากลิงค์ด้านล่าง
- หลังจากเริ่มโปรแกรมติดตั้งสำเร็จ คุณควรเห็นการตั้งค่า gitบนหน้าจอ ทำตามพร้อมท์ Next และ Finish เพื่อเสร็จสิ้นการติดตั้ง
git --version
เริ่มต้น
- Git Initialize Commands ใช้สำหรับสร้างหรือเริ่มต้นโครงการที่ควบคุมเวอร์ชันใหม่ Git ไม่ต้องการเซิร์ฟเวอร์ที่มีอยู่แล้วหรือสิทธิ์ของผู้ดูแลระบบ
- มีคำสั่งบางอย่างสำหรับ Initializaion ซึ่งแสดงไว้ด้านล่าง
git init:แปลงไดเร็กทอรีปัจจุบันเป็นที่เก็บ Gitgit clone: git clone ใช้เพื่อสร้างสำเนาของที่เก็บที่มีอยู่ ภายใน git clone เรียก git init ก่อนเพื่อสร้างที่เก็บใหม่git add:ไฟล์ไปที่พื้นที่จัดเตรียม
> `git add .` : all Files goes to staging area
> `git add file1.txt file2.txt` : specific Files goes to staging area
> `git add *.txt` : only extenction files staging area
> `git restore --staged FILE_NAME` : restore file from staging area
git push:มันจะผลักไฟล์จาก repo ในเครื่องไปยัง repo ระยะไกลgit fetch:มันจะใช้เพื่อนำเข้าไฟล์จาก repo ระยะไกลไปยัง repo ในเครื่องgit pull : เป็นการรวมกันของ 2 คำสั่งfetch และmerge> git init
> git add README.md
> git commit -m "commit"
> git branch -M main
> git remote add origin REPO_URL
> git push -u origin main
- ไฟล์กำหนดค่า Git ส่วนกลางถูกจัดเก็บไว้ในไฟล์ที่มีชื่ออยู่
.gitconfigในโฮมไดเร็กทอรีของผู้ใช้ ขึ้นอยู่กับระบบปฏิบัติการ: - มีคำสั่งเฉพาะบางอย่างเพื่อเก็บค่าเฉพาะ
> git config --global user.name ""
> git config --global user.email ""
> git config --global user.password ""
> git config --global core.editor "code --wait"
> git config --global -e
> git config --global credential.helper store : store the credentials
> git config --global --unset credential.helper : unset the credentials which are set
> git remote set-url origin https://[email protected]/USER_NAME/REPO_NAME.git
> git config --local user.name "UserName"
> git config --local user.email "email Address"
> git config --local user.password "personal Token"
> git config credential.helper store : store the credentials
> git config --local --unset credential.helper: unset the credentials which are set
> git commit -m "message"
> git commit --amend : Add Description or change commit message of the last previous commit
> git commit -am "message" : commit without stageing
> git reset --hard COMMIT_ID : delete old commit
> git reset --hard HEAD~COMMIT_NUMBER : delete old commit using HEAD pointer
> git reset --soft COMMIT_ID : delete old commit using HEAD pointer
> git show COMMIT_ID : show Actual Commit
> git revert Commit_ID : It will revert you code till Commit_ID
ซ่อนคอมไพล์
- จะนำการเปลี่ยนแปลงที่ไม่มีข้อผูกมัดของคุณบันทึกไว้เพื่อใช้ในภายหลัง และเปลี่ยนกลับจากสำเนาการทำงานของคุณ
git stash:ซ่อนการเปลี่ยนแปลงของ repo ในเครื่องgit stash pop:ซ่อนการเปลี่ยนแปลงที่ถูกซ่อนไว้ในขณะนี้
- git branch เป็นเวอร์ชันใหม่ของ repository หลัก
- สมมติว่าเราอยู่ในโปรเจ็กต์ขนาดใหญ่ และถ้าไคลเอนต์ต้องการอัปเดตฟีเจอร์ใดๆ โดยไม่กระทบกับโปรเจ็กต์ที่ใช้งานอยู่ การแตกสาขาจะมีประโยชน์
- you have to create a new branch in main repository after that work on it and when the work is completed merge the feature branch with main so the update is merge with the main branch.
> git branch Branch_Name : create new branch
> git checkout Branch_Name : change the branch
> git branch Old_Branch_Name New_Branch_Name : Rename branch
> git branch -D Branch_Name : Delete branch
> git log main..child : shows the unmarged commits
git merge Branch_Name : Marge child branch with parent
git merge --squash Branch_Name : Marge with squash (Remove History of sub branch commits and marge with single commit)
- The git rebase command allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together.
git rebase Branch_Name: Marge Using Rebase (Only changing the base of the first branch)
- git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD
git cherry-pick COMMIT_ID_1 COMMIT_ID_2: Marge ใช้การผูกมัดเฉพาะ





































![รายการที่เชื่อมโยงคืออะไร? [ส่วนที่ 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)