|
79 | 79 | $ git add .
|
80 | 80 | $ git commit -am [message]
|
81 | 81 |
|
82 | | -7. ### Commit changes (Workspace <-- Staging <-- Repository ) |
| 82 | +7. ### Undo Commit (Workspace <-- Staging <-- Repository ) |
83 | 83 |
|
84 | 84 | # Undo the last commit.
|
85 | 85 | $ git reset HEAD~1
|
|
90 | 90 | $ git push origin [branch]
|
91 | 91 |
|
92 | 92 |
|
93 | | -8. ### Repository synchronization from remote (Repository <-- Remote) |
| 93 | +9. ### Repository synchronization from remote (Repository <-- Remote) |
94 | 94 |
|
95 | 95 | # Download specific branch.
|
96 | 96 | $ git fetch origin [branch]
|
|
99 | 99 | $ git fetch --all
|
100 | 100 |
|
101 | 101 |
|
102 | | -9. ### Workspace synchronization from Repository (Workspace <-- Repository) |
| 102 | +10. ### Workspace synchronization from Repository (Workspace <-- Repository) |
103 | 103 |
|
104 | 104 | # merge the specified branch to the current branch.
|
105 | 105 | $ git merge [branch]
|
106 | 106 |
|
107 | 107 | # merge a branch into a target branch
|
108 | 108 | $ git merge [source branch] [target branch]
|
109 | 109 |
|
| 110 | +11. ### Workspace synchronization from remote (Workspace <-- Repository <-- Remote) |
110 | 111 |
|
111 | | -10. ### Workspace synchronization from remote (Workspace <-- Repository <-- Remote) |
112 | | - |
113 | | - # Retrieve the changes to the Remote Repository and merge with the local branch. |
| 112 | + # Retrieve the changes to the Remote Repository and merge with the local branch (fetch+merge) |
114 | 113 | $ git pull origin [branch]
|
115 | 114 |
|
116 | | - |
117 | 115 |
|
| 116 | +12. ### View Information |
| 117 | + |
| 118 | + # Display the changed files. |
| 119 | + $ git status |
118 | 120 |
|
119 | | -6. ### Remote branch synchronization from local |
| 121 | + # Display the version history of the current branch. |
| 122 | + $ git log |
120 | 123 |
|
121 | | - # Push the local specified branch to the Remote Repository. |
122 | | - $ git push [remote] [branch] |
| 124 | + # Display the commit history, and the changed files for each commit. |
| 125 | + $ git log --stat |
123 | 126 |
|
124 | | - # Push all the branches to the Remote Repository. |
125 | | - $ git push [remote] --all |
| 127 | + # Search commit history, according the keyword. |
| 128 | + $ git log -S [keyword] |
126 | 129 |
|
| 130 | + # Display all changes since a certain commit, occupying one line for one commit. |
| 131 | + $ git log [tag] HEAD --pretty=format:%s |
127 | 132 |
|
128 | | -4. ### Branching |
| 133 | + # Display all changes since a certain commit, and its "commit description" must meet the search criteria. |
| 134 | + $ git log [tag] HEAD --grep feature |
| 135 | + |
| 136 | + # Display the version history of a certain file. |
| 137 | + $ git log --follow [file] |
| 138 | + $ git whatchanged [file] |
| 139 | + |
| 140 | + # Display each diff related to the specified file. |
| 141 | + $ git log -p [file] |
| 142 | + |
| 143 | + # Display the past 5 commits. |
| 144 | + $ git log -5 --pretty --oneline |
| 145 | + |
| 146 | + # Display all the users who have committed, sorted by number of commits. |
| 147 | + $ git shortlog -sn |
| 148 | + |
| 149 | + # Display when and by whom the specified file was modified. |
| 150 | + $ git blame [file] |
| 151 | + |
| 152 | + # Display the difference between the Index and the Workspace. |
| 153 | + $ git diff |
| 154 | + |
| 155 | + # Display the difference between the Index and the previous commit. |
| 156 | + $ git diff --cached [file] |
| 157 | + |
| 158 | + # Display the difference between the Workspace and the latest commit of the current branch. |
| 159 | + $ git diff HEAD |
| 160 | + |
| 161 | + # Display the difference between two commits. |
| 162 | + $ git diff [first-branch]...[second-branch] |
| 163 | + |
| 164 | + # Display how many lines of code you have written today. |
| 165 | + $ git diff --shortstat "@{0 day ago}" |
| 166 | + |
| 167 | + # Show the metadata and the changed content for a certain commit. |
| 168 | + $ git show [commit] |
| 169 | + |
| 170 | + # Show the changed file for a certain commit. |
| 171 | + $ git show --name-only [commit] |
| 172 | + |
| 173 | + # Show the contents of a certain file for a certain commit. |
| 174 | + $ git show [commit]:[filename] |
| 175 | + |
| 176 | + # Show the latest commits of the current branch. |
| 177 | + $ git reflog |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +12. ### Branching |
129 | 182 |
|
130 | 183 | # List all local branches. (the asterisk denotes the current branch)
|
131 | 184 | $ git branch
|
|
156 | 209 | $ git branch -dr [remote/branch]
|
157 | 210 |
|
158 | 211 |
|
159 | | -5. ### Ignore files and folder |
| 212 | +13. ### Ignore files and folder |
160 | 213 |
|
161 | 214 | # Delete the files in the Workspace and put this deletion into the Index.
|
162 | 215 | $ git rm [file1] [file2] ...
|
|
165 | 218 | # Stop tracking the specified file, but the file will be remained in the Workspace.
|
166 | 219 | $ git rm --cached [file]
|
167 | 220 |
|
168 | | -6. ### Tag |
| 221 | +14. ### Tag |
169 | 222 |
|
170 | 223 | # List all tags.
|
171 | 224 | $ git tag
|
|
194 | 247 | # Create a new branch pointing to a certain tag
|
195 | 248 | $ git checkout -b [branch] [tag]
|
196 | 249 |
|
197 | | -6. ### View Information |
198 | | - |
199 | | - # Display the changed files. |
200 | | - $ git status |
201 | | - |
202 | | - # Display the version history of the current branch. |
203 | | - $ git log |
204 | | - |
205 | | - # Display the commit history, and the changed files for each commit. |
206 | | - $ git log --stat |
207 | | - |
208 | | - # Search commit history, according the keyword. |
209 | | - $ git log -S [keyword] |
210 | | - |
211 | | - # Display all changes since a certain commit, occupying one line for one commit. |
212 | | - $ git log [tag] HEAD --pretty=format:%s |
213 | | - |
214 | | - # Display all changes since a certain commit, and its "commit description" must meet the search criteria. |
215 | | - $ git log [tag] HEAD --grep feature |
216 | | - |
217 | | - # Display the version history of a certain file. |
218 | | - $ git log --follow [file] |
219 | | - $ git whatchanged [file] |
220 | | - |
221 | | - # Display each diff related to the specified file. |
222 | | - $ git log -p [file] |
223 | | - |
224 | | - # Display the past 5 commits. |
225 | | - $ git log -5 --pretty --oneline |
226 | | - |
227 | | - # Display all the users who have committed, sorted by number of commits. |
228 | | - $ git shortlog -sn |
229 | | - |
230 | | - # Display when and by whom the specified file was modified. |
231 | | - $ git blame [file] |
232 | | - |
233 | | - # Display the difference between the Index and the Workspace. |
234 | | - $ git diff |
235 | | - |
236 | | - # Display the difference between the Index and the previous commit. |
237 | | - $ git diff --cached [file] |
238 | | - |
239 | | - # Display the difference between the Workspace and the latest commit of the current branch. |
240 | | - $ git diff HEAD |
241 | | - |
242 | | - # Display the difference between two commits. |
243 | | - $ git diff [first-branch]...[second-branch] |
244 | | - |
245 | | - # Display how many lines of code you have written today. |
246 | | - $ git diff --shortstat "@{0 day ago}" |
247 | | - |
248 | | - # Show the metadata and the changed content for a certain commit. |
249 | | - $ git show [commit] |
250 | | - |
251 | | - # Show the changed file for a certain commit. |
252 | | - $ git show --name-only [commit] |
253 | | - |
254 | | - # Show the contents of a certain file for a certain commit. |
255 | | - $ git show [commit]:[filename] |
256 | | - |
257 | | - # Show the latest commits of the current branch. |
258 | | - $ git reflog |
259 | | - |
260 | 250 |
|
261 | 251 |
|
262 | 252 |
|
|
0 commit comments