-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProGit_Chapter2.flashup
251 lines (160 loc) · 7.98 KB
/
ProGit_Chapter2.flashup
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
* How do you initialize a repository in a directory?
`$ git init`
This creates a new subdirectory named .git that contains all your necessary repository files - a Git Repository skeleton.
* What are the 2 basic steps to start version controlling existing files?
`add` and `commit`
`$ git add *.c`
`$ git commit -m 'initial project version'`
* How do you clone an existing repository?
`
$ git clone [email protected]:memlab/ProGitFlashcards.git
`
This creates a directory named ProGitFlashCards, initializes a .git directory inside it, pulls down all the data for that repository and checks out a working cop of the latest version
* How do you check the status of your files?
`$ git status`
* How do you start tracking a new file?
`$ git add newFile`
Note: Git add can be used to both start tracking file and also update a modified file to staging. Remember when you use git commit, only the version of the file in staging will be commited.
* How do you update modified files to staging?
`$ git add modifiedFile`
Note: Git add can be used to both start tracking file and also update a modified file to staging. Remember when you use git commit, only the version of the file in staging will be commited.
* How do you tell git to ignore some specific files?
`$ cat .gitignore`
`.[oa]`
`~`
The first line tells Git to ignore file ending in `.o` or `.a`, the second line tells git to ignore files that end with a tilde `~`.
* How do you view changes that are not yet staged?
`$ git diff`
Note: This command will only show you changes that are still unstaged. If you've staged all of your changes, `git diff` will give you no output.
* How do you view changes that you have staged, but not yet commited?
`$git diff --cached`
* How do you commit your changes?
`$ git commit`
This launches the editor of your choice so that you can type your commit message.
Also, `$ git commit -m "Your Commit Message"`
can be used to commit your changes by typing your message inline.
* Can you skip the staging area?
* If yes, how?
`$ git commit -a -m 'Your Commit Message'`
* How do you remove a tracked file?
* How do you remove a tracked directory?
`$ git rm fileName`
`$ git rm -r`
Note: The next time you commit, the file will be gone and no longer tracked.
* How do you keep a file in your working tree but remove it from your staging area?
`$ git rm --cached fileName`
Note: This is particularly useful if you forgot to add something to your `.gitignore` file and accidentally added it, like a large log of compiled `.a` files.
* How do you move/rename a file notifying git?
`$ git mv file_from file_to`
Note : This is equivalent to running something like
`$ mv README.txt README`
`$ git rm README.txt`
`$ git add README`
* How do you view the commit history?
`$ git log`
Note: With no arguments `git log` lists the commits made in that repository in reverse chronological order.
* How do you view the commit history in different formats?
`$ git log --pretty=oneline`
`$ git log --pretty=short`
`$ git log --pretty=full`
`$ git log --pretty=fuller`
*How do you specify your own output log format?
`
$ git log --pretty = format:"%h - %an, %ar : %s"
`
Note : The above command lists each commit with its SHA-1 checksum, the username, the date written and the commit message.
* List the output log formats options and their tasks.
`%H` Commit hash
`%h` Abbreviated commit hash
`%T` Tree hash
`%t` Abbreviated tree hash
`%P` Parent hashes
`%p` Abbreviated parent hashes
`%an` Author name
`%ae` Author e-mail
`%ad` Author date (format respects the --date= option)
`%ar` Author date, relative
`%cn` Committer name
`%ce` Committer email
`%cd` Committer date
`%cr` Committer date, relative
* List the output log options and their tasks.
`-p`: Show the patch introduced with each commit.
`--stat`: Show statistics for files modified in each commit.
`--shortstat`: Display only the changed/insertions/deletions line from the --stat command.
`--name-only`: Show the list of files modified after the commit information.
`--name-status`: Show the list of files affected with added/modified/deleted information as well.
`--abbrev-commit`: Show only the first few characters of the SHA-1 checksum instead of all 40.
`--relative-date`: Display the date in a relative format (for example, "2 weeks ago") instead of using the full date format.
`--graph`: Display an ASCII graph of the branch and merge history beside the log output.
`--pretty`: Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format).
* How do you limit your log output?
`$ git log --since=2.weeks`
Note: This command works with lots of formats you can specify a specific date (2008-01-15) or a relative date such as "2 years 1 day 3 minutes ago".
* List the `git log` filter options.
`-(n)`: Show only the last n commits
`--since, --after`: Limit the commits to those made after the specified date.
`--until, --before`: Limit the commits to those made before the specified date.
`--author`: Only show commits in which the author entry matches the specified string.
`--committer`: Only show commits in which the committer entry matches the specified string.
* How do you change your last commit?
`$ git commit --amend`
Note: This can be used when you commit too early and possibly forget to add some files. This command takes your staging area and uses it for commit. As an example, if you commit and realize you forgot to stage changes in a file you wanted to add to this commit you can do,
`$ git commit -m 'initial commit'`
`$ git add forgotten_file`
`$ git commit --amend`
* How do you unstage a staged file?
`$ git reset HEAD fileName`
* How do you unmodify a modified file?
`$ git checkout --fileName`
Note: Realize that by using this command, any changes you made to your file are gone. You just copied another file over it.
* How do you see which remote servers you have configured?
`$ git remote`
Note: If you've cloned your repository, you should see origin. You can also specify `-v`, which shows the URL that Git has stored.
* How do you add a remote repository?
`
$ git remote add shortName [email protected]:memlab/ProGitFlashcards.git
`
Note: Now you can use shortName on the command line in lieu of the whole URL.
* How do you fetch from your remotes?
`$ git fetch [remote-name]`
* How do you push to your remotes?
`$ git push [remote-name] [branch-name]`
Example: `git push origin master`
* How do you see more information about a particular remote?
`$ git remote show [remote-name]`
* How do you rename a remote?
`$ git remote rename oldName newName`
* How do you remove a remote?
`$ git remote rm remoteName`
* How do you list the available tags in a Git workspace?
`$ git tag`
Note: You can also search for tags with a particular patters using `$ git tag -l 'v1.4.2*'`
* How do you create a annotated tag?
`$ git tag -a v1.4 -m 'Tagging Message'`
If you run `git show` on the tag , you can see the GPG signature attached to it.
* What is a lightweight tag?
* How do you create one?
A lightweight tag basically stores the commit checksum in a file. No other Information is kept
`$ git tag v1.4-lw`
Note: If you dont specify a message for an annotated tag, Git launches your editor so you can type it in.
* How do you create a signed tag?
`$ git tag -s v1.5 -m 'Your Tagging Message '`
Note: This command signs your tag with GPG, assuming you have a private key.
* How do you verify a signed tag?
`$ git tag -v v1.4.2.1`
Note: This command uses GPG to verify the signature. You need the signer's public key in your keying for this to work properly.
* You forgot to tag the project at v1.2, which was a few commits before.
*How do you create it now?
`git tag -a v1.2 [commit-checksum]`
Example: `$ git tag -a v1.2 9fceb02`
* How do you push a tag to the remote servers?
`$ git push origin [tagname]`
Example: `$ git push origin v1.5`
* How do you create a git alias?
`$ git config --global alias.[aliasName] [command]`
Example:
`
$ git config --global alias.last 'log -1 HEAD'
`
Now when you run `$ git last`, you can see the last commit.