-
Notifications
You must be signed in to change notification settings - Fork 0
/
Git-Getting Started
169 lines (85 loc) · 4.92 KB
/
Git-Getting Started
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
INSTALLING GIT
1. Mac : http://sourceforge.net/projects/git-osx-installer/
2. Windows : https://git-scm.com/download/win
3. Linux : apt-get install git-core OR yum install git-core
ABOUT GIT
1. Git is a version control tool that saves changes to groups of files so you can revert back if needed.
2. There are different types of version control tools
a. Local Version Control saves changes to files in a database
b. Centralized Version Control saves changes to a shared server
c. Distributed Version Control allows for easier sharing of files then LVC and also eliminates problems that could occur if access to the server is lost under a CVC system.
d. DVC clients have a complete backup of the files on their computer. If the server is lost the client just waits to regain contact and then uploads changes.
3. When you commit changes to files Git stores a reference of what the files look like at that moment. If a file isn't changed it isn't stored again.
4. Each client has a complete history of all changes stored locally. The client can also access all changes made to the files historically with a simple command. Also those files cannot be changed without Git knowing and changes are difficult to lose.
5. Files transition between 3 states with Git
a. Modified Files are files that have been recently changed
b. Staged Files have been marked to be saved
c. Committed Files are those that have been saved
6. Git saves all file changes to a directory as a compressed database.
a. You modify files in Working Directory
b. You notify that want to save changes in your Staging Area
c. After you Commit the file changes are saved in the Git directory
USING GIT
1. git config --global user.name "Ramprasade10 "
2. git config --global user.email ramprasade10@gmail.com
3. git config --global core.editor "vim" # Set editor as vim
4. git config --global core.editor "edit -w" # Set editor as Text Wrangler Mac
5. git config --list # Show settings
6. git help OR git help [COMMAND] OR git help add
7. ---------------- Track a directory ----------------
a. Go to directory
b. ls -a shows all files
c. git init # Creates the .git directory
8. ---------------- Start tracking files ----------------
a. By type : git add *.java
b. By name : git add AndroidManifest.xml
9. ---------------- Ignore Files ----------------
a. Create a .gitignore file
b. https://github.com/github/gitignore
10. ---------------- git commit -m 'Initial project version'
a. Commits the changes and sets an abbreviated commit message
11. ---------------- git status ----------------
a. Shows the state of your files meaning if they are tracked, have been modified and the branch your on.
12. ---------------- Stage A Modified File ----------------
a. Change the file and save
b. git diff # Shows what you changed, but haven't staged
c. git add AndroidManifest.xml # Stage file
d. git diff --cached # Shows what has been staged, but not committed
13. ---------------- Commit The Changes ----------------
a. commit # Opens the editor we defined above or vi
b. In vi click [ESC] i to enter insert mode
c. Type a heading that briefly explains the changes in 50 characters or less
d. Describes the original problem that is being addressed
e. Describes the specific change being made
f. Describes the result of the change
g. Describes any future improvements
h. Post a closes bug notation Closes-Bug: #1291621
i. Hit [ESC] and type wq to save and exit
j. git commit -a -m 'Changed comment' # Skips staging and commit message
14. ---------------- Remove a File ----------------
a. rm DeleteMe.txt # If you remove a file it shows as "Changed but not updated"
b. git status # If you remove a file it shows as "Changed but not updated"
c. git rm DeleteMe.txt
d. git status # Shows that the file was deleted
e. If you have committed a file to be removed you must add the -f option
f. git rm --cached DeleteMe.txt # Keep file, but remove from staging area
g. git mv DeleteMe.txt Delete.txt # Renames a file
15. ---------------- Log Commit History ----------------
a. git log # Shows all of the previous commit messages in reverse order
b. git log --pretty=oneline # Shows commits on one line
c. git log --pretty=format:"%h : %an : %ar : %s"
I. %h - Abbreviated Hash
II. %an - Authors Name
III. %ar - Date Changed
IV. %s - First Line of Comment
d. git log -p -2 # Shows the last 2 commit changes
e. git log --stat # Prints abbreviated stats
f. git log --since=1.weeks # Show only changes in the last week
g. git log --since="2014-04-12" # Show changes since this date
h. git log --author="Ramprasade10" # Changes made by author
i. git log --before="2014-04-13" # Changes made before this date
16. ---------------- Undoing a Commit ----------------
a. git commit --amend # If you want to change your previous commit
b. Normally done if you forgot to stage a file, or to change the commit message
17. ---------------- Unstage a File ----------------
a. git reset HEAD AndroidManifest.xml