-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_basic
More file actions
77 lines (53 loc) · 4.34 KB
/
git_basic
File metadata and controls
77 lines (53 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Github, git note
>> Create repository <<
git init <directory> OR /directory$ git init //สำหรับสร้าง repository ในแก่ directory นั้นๆ
git clone <repository path> <directory> // clone มาใส่ใน directory
git clone <repository path> // clone มาทั้ง directory
>> Configuration <<
git config --global user.name peeratat // กำหนด username ชื่อ peeratat โดย --global คือให้ใช้ config กับทุกๆ repository ในเครื่อง
git config --global user.email peeratat1995@gmail.com //กำ useremail ว่า peeratat1995@gmail
touch .gitignore //สร้างไฟล์ .gitignore ในตำแหน่ง root directory เพื่อให้ git ไม่ต้องสนใจไฟล์เหล่านี้
<<<ในไฟล์ .gitignore>>>
fileName.js
*.png
*.jpg
>> Move state <<
git add <file1> <file2> ... <fileN> // ทำการ tracking และ staging ไฟล์แต่ละไฟล์ กี่ไฟล์ก็ได้แล้วแต่เราลงใน repository
git add -u // ทำการ staging ไฟล์ทุกๆไฟล์ที่ tracked อยู่แล้ว
git add -A // ทำการ tracking และ staging ไฟล์ทุกๆไฟล์ ยกเว้นไฟล์ที่ถูกignore
git add . // staging ทุกไฟล์ที่มีการเปลี่ยนแปลง
git rm <file> // delete and untrack file
git rm --cached <file> // untrack file
git reset <file> // unstage file
git commit -m "note" // snapshot ไฟล์ทุกไฟล์ที่อยู่ใน index ( อยู่ในสถานะ staged)
git commit --amend // แก้ไขcommitล่าสุดโดยรวมกับการเปลี่ยนแปลงล่าสุด
git commit -a -m "note" === git add -u && git commit -m "note"
>> Monitor <<
git log // โชว์ checksum, date, note ของการ commit ก่อนหน้านี้
git log --oneline
git status // โชว์ status ของไฟล์ต่างๆ ( ไม่รวมที่ ingnore )
git diff HEAD // ตรวจสอบความแตกต่างของปัจจุบันกับ HEAD
git config --list // show config list
git branch // view all branch
git remote -v // view all remote url
>> Checkout <<
git checkout <commit> // ย้อนกลับไปที่ commit ที่ต้องการ แต่ถ้าหากแก้ไขแล้ว commit ณ ตำแหน่งนั้นจะเป็นการแตก branch
<commit> : checksum(6+), HEAD( commit ล่าสุด ), HEAD~2 ( commit อันที่2ก่อนล่าสุด )
git checkout master // กลับไปที่ branch master
git checkout <commit> <file> // ย้อนกลับไปที่ commit ที่ต้องการแบบแยกไฟล์ ถ้าหากแก้ไขแล้ว commit ณ ตำแหน่งนั้นจะไม่แตก branch แต่ถือว่าเป็น commit ใหม่ของ branch ปัจจุบันเลย
>> Undo <<
git revert <commit> // ย้อนกลับไปที่ <commit> แล้วบันทึกผลการย้อนโดยการ commit
git reset --hard HEAD // ยกเลิกการเปลี่ยนแปลงทุกอย่างแล้วกลับไปที่ <commit> ย้อนเฉยๆ ไม่ได้commitเพิ่ม
>> Branch <<
git branch <new-branch-name> // create new branch
git checkout <branch-name> // move to new-branch-name branch
>> merge <<
//on master branch
git merge <branch-name> // merge new-branch-name to master branch
git branch -d <branch-name> // delete new-branch-name branch
>> Remote <<
git remote add origin https://github.com/Rhapzody/git_tutorial.git // add remote-url name=origin=https://github.com/Rhapzody/git_tutorial.git
git remote set-url <remote-name> <remote-url>
git push origin master // push update to online repo. (origin=https://github.com/Rhapzody/git_tutorial.git, branch=master)
git push -u origin master // push and save origin master >> can write only git push
git pull origin master // update local repository from origin master