-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitLearning.txt
109 lines (77 loc) · 2.93 KB
/
GitLearning.txt
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
git init
git add
git commit -m "version explaination" ("-a" for "--all")
git status
git diff <filename> (to highlight the difference)
git diff HEAD -- <filename> (to show the difference between file in workplace and newest version)
git log
git log --pretty=oneline
git reflog (show your command in history)
git reset --hard <commit_id>
git reset --hard ^HEAD (to move back)
git reset --hard HEAD^ (to mave on)
//3 ways to go back:
--------------------------------
//1-havent been added or commited
git checkout -- <filename> (to let the file in workplace turn to the last version added or commited)
//2-have been added but not commited
git reset HEAD <filename>
//3-have been commited (must not been uploaded to the remote repository)
git reset --hard <id>
----------------------------------
File delete:
rm <filename> (to delete in the repository)
git rm <filename> (to delete in the stage)
--------------------------
use them together with former commands.
Link to a remote repository:
| git remote add https://github.com/<user>/<repositoryname>
|or git remote add git@github.com:<user>/<repositoryname>
git push -u origin master (first time to push)
git push origin master
Clone:
| git clone https://github.com/<user>/<repositoryname>
|or git clone add git@github.com:<user>/<repositoryname>
----------------------------------------------
best use the git protocal rather than http
Set branches:
git checkout-b dev
equals to:
git branch dev (establish a branch "dev")
git checkout dev (switch to branch "dev")
git branch (to check the status of branches)
git log --graph --pretty=oneline --abbrev-commit
git merge --no-ff -m "<explaination>" <branch_name>
git branch -d <branch_name>
git branch -D <branch_name>
-------------------------------------------------
git stash
git stash list
git stash pop
git stash apply stash@{0}
-----------------------------
git remote (to check the origin)
git remote -v (to check the address of origin)
git push origin <branch_name>
=============================
git branch --set-upstream dev origin/dev (to set the reflection between local and remote)
git branch -b dev orgin/dev
git pull
-----------------------------
git tag <tag> (to tag on the active branch)
git tag (to show the tag)
git tag <tag> <commit_id>
git show <tag>
git tag -a <tag> -m "<explanation>" <commit_id>
git tag -s <tag> -m "<explanation>" <commit_id> (to set a key)
git tag -d <tag>
git push origin <tag>
git push origin --tags
git push origin :refs/tags/<tag> (first, del localy; then push to remote)
-------------------------------
To ignore:
https://github.com/github.gitigore
establish a file named ".gitignore"
git config --global alias.<abbr> <NAME> (to define a abbrevation)
git config --global alias.<A> '<B>' (#define A B)
git config --global alias.lg "log --color --graph --pretty=format:'Cred%h%Creset -C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"