├── .gitignore
├── images
├── git-rm.png
├── git-add.png
├── git-blame.png
├── git-clean.png
├── git-diff.png
├── git-log.png
├── git-merge.png
├── git-reset.png
├── git-show.png
├── git-stash.png
├── git-tag.png
├── red-line.gif
├── git-bisect.png
├── git-branch.png
├── git-commit.png
├── git-config.png
├── git-rebase.png
├── git-restore.png
├── git-revert.png
├── git-status.png
├── git-checkout.png
├── github-upload.png
├── mergevsrebase.png
├── stack-data-structure.png
├── updating-coming-soon.gif
└── create-an-empty-git-repository.png
├── README.md
└── READMEir.md
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | **/.idea/
3 | google1c69f44963c044dd.html
--------------------------------------------------------------------------------
/images/git-rm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-rm.png
--------------------------------------------------------------------------------
/images/git-add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-add.png
--------------------------------------------------------------------------------
/images/git-blame.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-blame.png
--------------------------------------------------------------------------------
/images/git-clean.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-clean.png
--------------------------------------------------------------------------------
/images/git-diff.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-diff.png
--------------------------------------------------------------------------------
/images/git-log.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-log.png
--------------------------------------------------------------------------------
/images/git-merge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-merge.png
--------------------------------------------------------------------------------
/images/git-reset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-reset.png
--------------------------------------------------------------------------------
/images/git-show.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-show.png
--------------------------------------------------------------------------------
/images/git-stash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-stash.png
--------------------------------------------------------------------------------
/images/git-tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-tag.png
--------------------------------------------------------------------------------
/images/red-line.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/red-line.gif
--------------------------------------------------------------------------------
/images/git-bisect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-bisect.png
--------------------------------------------------------------------------------
/images/git-branch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-branch.png
--------------------------------------------------------------------------------
/images/git-commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-commit.png
--------------------------------------------------------------------------------
/images/git-config.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-config.png
--------------------------------------------------------------------------------
/images/git-rebase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-rebase.png
--------------------------------------------------------------------------------
/images/git-restore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-restore.png
--------------------------------------------------------------------------------
/images/git-revert.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-revert.png
--------------------------------------------------------------------------------
/images/git-status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-status.png
--------------------------------------------------------------------------------
/images/git-checkout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/git-checkout.png
--------------------------------------------------------------------------------
/images/github-upload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/github-upload.png
--------------------------------------------------------------------------------
/images/mergevsrebase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/mergevsrebase.png
--------------------------------------------------------------------------------
/images/stack-data-structure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/stack-data-structure.png
--------------------------------------------------------------------------------
/images/updating-coming-soon.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/updating-coming-soon.gif
--------------------------------------------------------------------------------
/images/create-an-empty-git-repository.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmad-mirzaei/git-commands-and-description/HEAD/images/create-an-empty-git-repository.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Git Commands & Description
4 |
5 | ## Description
6 | _[Git](https://git-scm.com/doc) commands are stored in this directory along with their brief descriptions. We welcome translations into other languages._
7 |
8 | ---
9 |
10 | - ### **Translated versions**
11 | - [Persian Version - فارسی](READMEir.md)
12 |
13 | ---
14 |
15 | ### **List of commands**
16 |
17 | | Row | Title | Row | Title | Row | Title | Row | Title |
18 | |:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
19 | | 1 | [Init](#git-init) | 7 | [Log](#git-log) | 13 | [Rebase](#git-rebase) | 19 | [Reset](#git-reset) |
20 | | 2 | [Status](#git-status) | 8 | [Blame](#git-blame) | 14 | [Stash](#git-stash) | 20 | [Revert](#git-revert) |
21 | | 3 | [Add](#git-add) | 9 | [Show](#git-show) | 15 | [Diff](#git-diff) | 21 | [Bisect](#git-bisect) |
22 | | 4 | [Rm](#git-rm) | 10 | [Config](#git-config) | 16 | [Checkout](#git-checkout) | 22 | [Upload Project](#upload-project) |
23 | | 5 | [Commit](#git-commit) | 11 | [Branch](#git-branch) | 17 | [Restore](#git-restore) | | |
24 | | 6 | [Tag](#git-tag) | 12 | [Merge](#git-merge) | 18 | [Clean](#git-clean) | | |
25 |
26 | ---
27 |
28 |
29 | ##
30 | 
31 |
32 | | commands | descriptions |
33 | |-----|-----|
34 | | `git -v` or `git --version` | Check the installed version of Git |
35 | | `git init` | introducing the project to Git or initializing it |
36 | | `git` or `git help` | Show the general Git help |
37 |
38 |
39 | 👆[list of commands](#go-to-the-command-list)
40 |
41 | ---
42 |
43 |
44 | ##
45 | 
46 |
47 | | commands | descriptions |
48 | |-----|-----|
49 | | `git status` | Viewing the current status of project files |
50 | | `git status --short` | View the summary of the current project file status |
51 | | `git status -s` | View the summary of the current project file status |
52 |
53 |
54 | 👈[previous](#git-init) | [list of commands](#go-to-the-command-list)👆
55 |
56 | ---
57 |
58 |
59 | ##
60 | 
61 |
62 | | commands | descriptions |
63 | |-----|-----|
64 | | `git add [file-name]` | it takes the selected file to the `staging area` |
65 | | `git add .` | it takes all files and project changes to the `staging area` |
66 | | `git add -A` | it takes all files and changes of the project to the staging area, just like the previous command |
67 | | `git add *.AnExtension` -> `git add *.css` | it takes all of the files with the selected extension to the `staging area` |
68 |
69 |
70 | 👈[previous](#git-status) | [list of commands](#go-to-the-command-list)👆
71 |
72 | ---
73 |
74 |
75 | ##
76 | 
77 |
78 | | commands | descriptions |
79 | |-----|-----|
80 | | `git rm [file name]` or `git rm -r [file name]` | it removes the selected file from the project |
81 | | `git rm -- *.AnExtension` -> `git rm -- *.py` | it removes all files that have the selected extension from the project |
82 | | `git rm --cached --ignore-unmatch *.js` | it ignores all the files with the selected extension and takes it to the [working directory] |
83 | | `git rm --cached [file name]` -> `git rm --cached .` | it takes the file or all the files that have gone to the staging area to the [working directory] |
84 | | `git rm -rf --cached .` | it tkes all the files from `the local repository` to `working directory` |
85 |
86 |
87 | 👈[previous](#git-add) | [list of commands](#go-to-the-command-list)👆
88 |
89 | ---
90 |
91 |
92 | ##
93 | 
94 |
95 | | commands | descriptions |
96 | |-----|-----|
97 | | `git commit -m [message]` | it takes staging area changes to the repository with a related message |
98 | | `git commit -am [message]` or `git commit -a -m [message]` | it takes the files that are already created in the project (and the files which are chainging) directly to the repository; But if a file is newly created, it must first be added to the staging area and then added to the repository with the suitable commit
`new file --> git add "file name" --> git commit -m "message"`
`modified file --> git commit -am "message" --> git commit -a -m "message"`|
99 | | `git commit --amend -m [message]` | Renaming the last commit |
100 | | `git commit --amend -am [message]` or `git commit --amend -a -m [message]` | it adds the last working directory changes to the last commit |
101 |
102 |
103 | 👈[previous](#git-rm) | [list of commands](#go-to-the-command-list)👆
104 |
105 | ---
106 |
107 |
108 | ##
109 | 
110 |
111 | | commands | descriptions |
112 | |-----|-----|
113 | | `git tag` or `git tag -l` | Displays the list of tags in the project |
114 | | `git tag [tag name]` -> `git tag 3.12.0` | if we put a version or a special name in front of the command, it will be considered for the last commit |
115 | | `git tag 3.13.0 [commit-hash]` -> `git tag v5.2.0 6d2ef95` | By putting the version or a name for the tag plus the hash coad of the selected commit, we can tag our commits |
116 | | `git show [tag name]` -> `git show 3.13.2` | Viewing the changes in every tag |
117 | | `git tag -d [tag name]` -> `git tag -d 3.12.2` | Removing the tag |
118 | | `git tag -f [tag name] [commit-hash]` -> `git tag -f v2.1.1 6d2ef95` | Removing a tag name from one comit and put the same name for another comite |
119 | | `git tag -l '13.*'` - `git tag -l '*.0'` - `git tag -l '*.1.*'` | Searching in tags |
120 |
121 |
122 | 👈[previous](#git-commit) | [list of commands](#go-to-the-command-list)👆
123 |
124 | ---
125 |
126 |
127 | ##
128 | 
129 |
130 | | commands | descriptions |
131 | |-----|-----|
132 | | `git log` | it returns the changes and commits of the project |
133 | | `git log --oneline` | it returns the changes and commits of the project in a summarized and short form |
134 | | `git log --oneline --all` | viewing all commits and seeing the position of origin and head |
135 | | `git log --stat` | it reverts the project changes completely |
136 | | `git log --graph` | it returns the commit information graphically |
137 | | `git log --graph --oneline` | it returns the commits in a graphic , detailed and summeraized way |
138 | | `git log --after="25-10-12"` | it returns the commits after a specified date |
139 | | `git log --before="25-10-12"` | it returns the commits before a specified date |
140 | | `git log --author="user-name"` | it returns the commits of the selected author or user along with the date and time of their insertion |
141 |
142 |
143 | 👈[previous](#git-tag) | [list of commands](#go-to-the-command-list)👆
144 |
145 | ---
146 |
147 |
148 | ##
149 | 
150 |
151 | | commands | descriptions |
152 | |-----|-----|
153 | | `git blame [file name]` | Viewing the `author's name` of the codes in the file, the date of entry, and the commit time |
154 | | `git blame -e [file name]` | Viewing the `author's email` of the codes in the file, the date of entry, and the commit time |
155 | | `git blame [file name] -L [start-line],[end-line]` | Viewing the author's details of the code in a file, from one line to another |
156 | | `git blame -L [start-line],[end-line] [file-name]` | It is similar to the previous command with a slight rearrangement of the instructions |
157 |
158 |
159 | 👈[previous](#git-log) | [list of commands](#go-to-the-command-list)👆
160 |
161 | ---
162 |
163 |
164 | ##
165 | 
166 |
167 | | commands | descriptions |
168 | |-----|-----|
169 | | `git show` | Viewing all changes in the latest commit |
170 | | `git show [commit-hash]` | Viewing the changes in the specific commit using its commit hash |
171 | | `git show [commit-hash] --stat` | It displays the changes made in the specific commit in a summarized form along with the author's details |
172 | | `git show [commit-hash] --path` | Viewing the actual differences made in the specific commit |
173 | | `git show [tag name]` | Viewing the changes within each tag |
174 |
175 |
176 | 👈[previous](#git-blame) | [list of commands](#go-to-the-command-list)👆
177 |
178 | ---
179 |
180 |
181 | ##
182 | 
183 |
184 | | commands | descriptions |
185 | |-----|-----|
186 | | `git config --list` | It displays a list of all the configuration settings currently present in your installed version of Git, such as local settings, global settings, and system settings |
187 | | `git config --local alias.[name] [command-name]` -> `git config --local alias.com commit` | With this command, we can choose shorter and more concise names for Git commands in our local environment |
188 | | `git config --global alias.com commit` | If we want to use an alias across all our projects, we use the word `global` instead of `local`, like in this command where we have shortened **`commit`** to **`com`** |
189 | | `git config --global user.name [your-name]` & `git config --global user.email [your-email]` | Setting the username and email for `all projects` |
190 | | `git config --global user.name` & `git config --global user.email` | Viewing the username or email that we have selected for `all projects` |
191 | | `git config user.name [your-name]` & `git config user.email [your-email]` | Setting the username or email for `a specific project` |
192 | | `git config user.name` or git `config user.email` | Viewing the username or email that we have selected for a specific project |
193 |
194 |
195 | 👈[previous](#git-show) | [list of commands](#go-to-the-command-list)👆
196 |
197 | ---
198 |
199 |
200 | ##
201 | 
202 |
203 | | commands | descriptions |
204 | |-----|-----|
205 | | `git branch` | Viewing the names of the project's branches and the branch we are currently on |
206 | | `git branch -a` | Viewing the list of all branches, including both local and remote branches |
207 | | `git branch origin --delete [branch-name]` | Deleting a remote branch |
208 | | `git branch [new-branch]` | Creating a new branch |
209 | | `git switch [branch-name]` | Switching from one branch to another |
210 | | `git switch -c [new-branch-name]` | Creating a new branch and switching to it |
211 | | `git branch -d [branch-name]` | Deleting a branch that has had no changes made to it after creation |
212 | | `git branch -D [branch-name]` | It is used to delete a branch where changes and commits have been made. You should not be on the branch you want to delete; instead, you need to switch to another branch and then delete the previous branch |
213 | | `git branch -m [new-name]` or `git branch -m [branch-name] [new-name]` | Renaming the desired branch. The second method is used when, for example, we are on branch A and want to rename branch B. In this case, there's no need to switch to branch B |
214 |
215 |
216 | 👈[previous](#git-config) | [list of commands](#go-to-the-command-list)👆
217 |
218 | ---
219 |
220 |
221 | ##
222 | 
223 |
224 | | commands | descriptions |
225 | |-----|-----|
226 | | `git merge [feature-branch]` | Merging a feature branch into the main branch; to perform the merge, you need to be on the main branch, and after completing the operation, you should delete the feature branch |
227 | | `git merge [feature-branch] [main-branch]` | Merging without Switching to the Main Branch |
228 |
229 |
230 | 👈[previous](#git-branch) | [list of commands](#go-to-the-command-list)👆
231 |
232 | ---
233 |
234 |
235 | ##
236 | 
237 |
238 | | commands | descriptions |
239 | |-----|-----|
240 | | `git rebase [feature-branch]` | Merging a feature branch into the main branch
To merge a feature branch into the main branch, you must first switch to the main branch and then use this command |
241 | | `git rebase [feature-branch] [main-branch]` | Merging a feature branch into the main branch without switching to the main branch |
242 |
243 |
244 | ### How rebasing and merging work in branch integration
245 |
246 |
247 | 
248 |
249 |
250 | ### Comparison of rebase and merge
251 |
252 |
253 | | Merge | Rebase | Feature |
254 | |:-----:|:-----:|--------:|
255 | | ❌ | ✔️ | Modifies history |
256 | | ✔️ | ✔️ | Merges branches |
257 | | (merge commit) ✔️ | ❌ | Additional commits |
258 | | May make branch history complex ❌ | ✔️ | Keeps history clean |
259 | | Safer ✔️ | Risky (requires caution) 🚨 | Team collaboration |
260 |
261 | 🟢 **When to use Rebase:** When you want a clean history without extra commits.
262 | 🟢 **When to use Merge:** When working in a team environment and you don't want to rewrite history.
263 |
264 |
265 |
266 | 👈[previous](#git-merge) | [list of commands](#go-to-the-command-list)👆
267 |
268 | ---
269 |
270 |
271 | ##
272 | 
273 |
274 | | commands | descriptions |
275 | |-----|-----|
276 | | `git stash` or `git stash save` | You may want to make some changes in a branch that you plan to add to the project later. For this, we use stash, which acts as a holder or a draft |
277 | | `git stash save [message]` | When using stash, you can provide a name or message to describe the changes being saved |
278 | | `git stash show` | Viewing General Information About a File That Has Been Stashed |
279 | | `git stash list` | Viewing the List of Stashes |
280 | | `git stash show stash@{index}` | Viewing the full changes of any stash using its index. |
281 | | `git stash show -p stash@{index}` | Viewing the changes of a specific stash in more detail |
282 | | `git stash pop` | It returns the last item in the stash |
283 | | `git stash apply` | It applies the changes from the selected stash to the project without removing it from the stash list |
284 | | `git stash drop stash@{index}` | Delete the specific stash |
285 | | `git stash clear` | Delete all stashes. |
286 |
287 |
288 | 👈[previous](#git-rebase) | [list of commands](#go-to-the-command-list)👆
289 |
290 | ---
291 |
292 |
293 | ##
294 | 
295 |
296 | | commands | descriptions |
297 | |-----|-----|
298 | | `git diff` | Viewing or comparing `working directory` changes with `staging area` |
299 | | `git diff --name-only [branch-name]` | Viewing the names of files that have changed after a specific commit |
300 | | `git diff --staged` | Viewing or comparing the latest commit along with changes in the staging area |
301 | | `git diff head or [HEAD]` | Comparing the latest commit with the working directory |
302 | | `git diff [first-hash-commit] [second-hash-commit]` -> `git diff 28344dc 85d9a5b` or `git diff 28344dc..85d9a5b` | Viewing or comparing the changes between two commits |
303 | | `git diff 28344dc..85d9a5b [file-name]` | Viewing or comparing two commits in a file |
304 | | `git diff [first-branch] [second-branch]` or `git diff [first-branch]..[second-branch]` | Viewing or comparing the changes between two branches before they are merged |
305 | | `git diff HEAD^ HEAD` | Displaying the differences between the latest commit and the previous commit |
306 |
307 |
308 | 👈[previous](#git-stash) | [list of commands](#go-to-the-command-list)👆
309 |
310 | ---
311 |
312 |
313 | ##
314 | 
315 |
316 | | commands | descriptions |
317 | |-----|-----|
318 | | `git checkout [branch-name]` | You switch to the branch you have specified |
319 | | `git switch [branch-name]` | You switch to the branch you have specified |
320 | | `git checkout [hash-commit]` | When we want to bring the changes of the project to a specific commit in the past, we use this command. In this case, we say the `HEAD is detached` |
321 | | `git checkout -- [file-name]` | This command cancels the changes made to the files in the working directory and restores them to the last commit state |
322 | | `git checkout [hash-commit] [file-name]` | Reverting the changes of a specific file to a commit using its commit hash |
323 | | `git checkout HEAD~[number]` -> `git checkout HEAD~5` | Going back to a few commits earlier by specifying the number of moves from HEAD to previous commits |
324 | | `git checkout HEAD [file-name]` | Reverting the current changes of a file to the last commit made
Discard working directory changes |
325 | | `git checkout HEAD .` | When changes are made to several files in the working directory, but we don't want those changes to be applied, we use this command to discard all the changes
Discarding all changes in the working directory |
326 | | `git checkout -- .` | Discarding all changes in the working directory and reverting it to the state of the last commit |
327 | | `git checkout -b [new-branch-name]` | Creating a branch and switching to it |
328 |
329 |
330 | 👈[previous](#git-diff) | [list of commands](#go-to-the-command-list)👆
331 |
332 | ---
333 |
334 |
335 |
336 | ##
337 | 
338 |
339 | | commands | descriptions |
340 | |-----|-----|
341 | | `git restore [file-name]` | When we make changes to a file in the working directory, running this command reverts the changes to the last commit or HEAD, effectively discarding them |
342 | | `git restore --staged [file-name]` | When we create a new file and add it to the staging area, running this command will unstage it, returning it to an untracked state |
343 | | `git restore --source [hash-commit] [file-name] ` | This command is similar to the following command: `git checkout [commit-hash] [file-name]`; However, the difference is that the HEAD is not moved or detached. Essentially, we are telling Git to revert the specified file to a particular commit hash or source |
344 | | `git restore --source HEAD [file-name]` | Reverting changes to the last commit or HEAD |
345 | | `git restore --source HEAD~5 [file-name]` | Moving the HEAD to five commits back (this will revert the project changes to the state it was in five commits ago). |
346 |
347 |
348 | 👈[previous](#git-checkout) | [list of commands](#go-to-the-command-list)👆
349 |
350 | ---
351 |
352 |
353 | ##
354 | 
355 |
356 | | commands | descriptions |
357 | |-----|-----|
358 | | `git clean -h` | `clean` View command help |
359 | | `git clean -f -d [file-name]` | Deleting a file that has been created but has not yet been staged or committed |
360 |
361 |
362 | 👈[previous](#git-restore) | [list of commands](#go-to-the-command-list)👆
363 |
364 | ---
365 |
366 |
367 | ##
368 | 
369 |
370 | | commands | descriptions |
371 | |-----|-----|
372 | | `git reset --soft [hash-commit]` | By running this command, if the specified commit hash corresponds to four commits below, we go back to four commits earlier, and all the commits above it are removed from the repository. However, the files and changes made to the project are not deleted; instead, they are moved back to the staging area, allowing us to decide on them again |
373 | | `git reset [hash-commit]` or `git reset --mixed [hash-commit]` | It works similarly to the previous command, meaning it goes back to the previous commit and removes the commits above it from the repository. However, the difference is that if the changes are in the staging area, they are moved to the working directory, and if they are in the working directory, they become untracked |
374 | | `git reset --hard [hash-commit]` | The entire project is reset to the specified commit, including the working directory. This means all changes revert to the state of the chosen commit
**Note**: Untracked files are not removed by this command because Git does not recognize them. Therefore, no changes are applied to these files |
375 |
376 |
377 | 👈[previous](#git-clean) | [list of commands](#go-to-the-command-list)👆
378 |
379 | ---
380 |
381 |
382 | ##
383 | 
384 |
385 | | commands | descriptions |
386 | |-----|-----|
387 | | `git revert [hash-commit]` | This command is used when, for example, we have created a commit and later realize that it is not useful for the project. It allows us to remove all the code added in that commit and restore the code that was previously deleted.
**Important Note:** If we revert a commit that depends on another commit, we may encounter a conflict. To resolve this issue, we should use the reset command instead |
388 |
389 |
390 | 👈[previous](#git-reset) | [list of commands](#go-to-the-command-list)👆
391 |
392 | ---
393 |
394 |
395 | ##
396 | 
397 |
398 | | commands | descriptions |
399 | |-----|-----|
400 | | `git bisect start` | When the project has many commits and we encounter a bug, we use this command to find and fix the bug. This command performs a binary search through the commits to locate the problematic commit |
401 | | `git bisect good [hash-commit]` | To use binary search in commits, we first need to mark a commit where the bug did not exist. Then, we manage the search by marking commits as "good" or "bad" until we locate the commit that introduced the bug |
402 | | `git bisect bad` | We manage the search by marking commits as "good" or "bad" until we reach the commit that introduced the bug |
403 | | `git bisect reset` | After reaching the problematic commit and fixing the bug, this command is used to conclude the process |
404 |
405 |
406 | 👈[previous](#git-revert) | [list of commands](#go-to-the-command-list)👆
407 |
408 | ---
409 |
410 |
411 | ##
412 | 
413 |
414 | | commands | descriptions |
415 | |-----|-----|
416 | | `git clone [https-repository-link]` | Adding a copy of a repository to our local machine |
417 | | `echo "# git-review" >> README.md`
`git init`
`git add README.md`
`git commit -m "first commit"`
`git branch -M main`
`git remote add origin [repository-link]`
`git push -u origin main` | When we want to start a project from scratch and add it to Git and GitHub, these steps must be followed |
418 | | ``git remote add origin [repository-link]`
`git branch -M main`
`git push -u origin main`` | When the project has been worked on and added to Git, and only the final steps remain, these are the steps you need to follow |
419 | | `git remote` | This command helps to determine which remote service the project is connected to |
420 | | `git remote -v` | If we want more information about the remote, we use this command |
421 | | `git remote remove [remote-name]` | Removing the specified remote |
422 | | `git push [remote] [branch]` | The action of uploading the project's code to GitHub is called "push." To push the project to GitHub, we specify the remote name we have selected and the branch name to push the changes from that branch to the chosen remote |
423 | | `git push -u origin [main-branch]` | By running this command, the remote and branch are set for us, so there is no need to write them again to upload changes to GitHub. For future uploads, you can simply use the command: `git push` |
424 | | `git pull origin [main-branch]` | Bringing changes from the GitHub repository to the local project |
425 | | `git fetch [remote-name] [branch-name]` | When changes have been made by ourselves or colleagues on GitHub, and we want to review those changes before merging, we use this command. After running it, we won't see any specific output because the changes have gone to the remote branch. To view them, we use this command: `git branch -r` |
426 | | `git branch -r` | It is used to view remote branches |
427 | | `git switch -c [branch-name] origin/main`
or
`git checkout -b [branch-name] origin/main` | To view changes in a remote branch, you first need to create a new branch, observe the changes there, then merge it. Finally, after merging, delete the merged branch. For this, we will use the following command |
428 |
429 |
430 | 👈[previous](#git-bisect) | [list of commands](#go-to-the-command-list)👆
431 |
432 |
433 | ---
434 |
435 |
436 |
--------------------------------------------------------------------------------
/READMEir.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # دستورات گیت و توضیحات
4 |
5 | ## توضیحات
6 | _دستورات [گیت](https://git-scm.com/doc) به همراه توضیحات مختصر آنها در این ریپوزیتوری فهرست می شوند؛ از ترجمه به زبانهای دیگر استفبال می شود_.
7 |
8 | ---
9 |
10 | - ### **ورژن های ترجمه شده**
11 | - [Persian Version - فارسی](READMEir.md)
12 |
13 | ---
14 |
15 |
16 |
17 | ### **فهرست دستورات**
18 |
19 | | ردیف | عنوان | ردیف | عنوان | ردیف | عنوان | ردیف | عنوان |
20 | |:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
21 | | 1 | [Init](#git-init) | 7 | [Log](#git-log) | 13 | [Rebase](#git-rebase) | 19 | [Reset](#git-reset) |
22 | | 2 | [Status](#git-status) | 8 | [Blame](#git-blame) | 14 | [Stash](#git-stash) | 20 | [Revert](#git-revert) |
23 | | 3 | [Add](#git-add) | 9 | [Show](#git-show) | 15 | [Diff](#git-diff) | 21 | [Bisect](#git-bisect) |
24 | | 4 | [Rm](#git-rm) | 10 | [Config](#git-config) | 16 | [Checkout](#git-checkout) | 22 | [Upload Project](#upload-project) |
25 | | 5 | [Commit](#git-commit) | 11 | [Branch](#git-branch) | 17 | [Restore](#git-restore) | | |
26 | | 6 | [Tag](#git-tag) | 12 | [Merge](#git-merge) | 18 | [Clean](#git-clean) | | |
27 |
28 | ---
29 |
30 |
31 | ##
32 | 
33 |
34 | | دستورات | توضیحات |
35 | |-----|-----:|
36 | | `git -v` or `git --version` | مشاهده ی ورژن نصب شده ی گیت |
37 | | `git init` | معرفی کردن پروژه به گیت یا اینیشیالایز کردن آن (ایجاد یک ریپوزیتوری یا مخزن خالی در لوکال شما) |
38 | | `git` or `git help` | نمایش راهنمای کلی گیت |
39 |
40 |
41 | 👆[برو به فهرست](#go-to-the-command-list)
42 |
43 | ---
44 |
45 |
46 | ##
47 | 
48 |
49 | | دستورات | توضیحات |
50 | |-----|-----:|
51 | | `git status` | ( working directory - staging area - head ) مشاهده ی موقعیت فعلی فایل های پروژه؛ |
52 | | `git status --short` | مشاهده ی موقعیت فعلی فایل های پروژه به صورت خلاصه شده |
53 | | `git status -s` | مشاهده ی موقعیت فعلی فایل های پروژه به صورت خلاصه شده |
54 |
55 |
56 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#create-empty-repository)👈
57 |
58 | ---
59 |
60 |
61 | ##
62 | 
63 |
64 | | دستورات | توضیحات |
65 | |-----|-----:|
66 | | `git add [file-name]` | [staging area] فایل مورد نظر را می برد به مرحله ی |
67 | | `git add .` | [staging area] تمامی فایل ها و تغییرات پروژه را می برد به مرحله ی |
68 | | `git add -A` |[staging area] همانند دستور قبلی تمامی فایل ها و تغییرات پروژه را می برد به مرحله ی |
69 | | `git add *.AnExtension` -> `git add *.css` |[staging area] تمامی فایل هایی که پسوند مورد نظر را داشته باشند را می برد به مرحله ی |
70 |
71 |
72 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-status)👈
73 |
74 | ---
75 |
76 |
77 | ##
78 | 
79 |
80 | | دستورات | توضیحات |
81 | |-----|-----:|
82 | | `git rm [file name]` or `git rm -r [file name]` | فایل مورد نظر را از پروژه حذف می کند |
83 | | `git rm -- *.AnExtension` -> `git rm -- *.py` | تمامی فایل هایی که پسوند مورد نظر را داشته باشند از پروژه حذف می کند |
84 | | `git rm --cached --ignore-unmatch *.js` | [working directory] تمامی فایل های با پسوند مورد نظر را می برد به مرحله ی |
85 | | `git rm --cached [file name]` -> `git rm --cached .` | [working directory] تمامی فایل های با پسوند مورد نظر را نادیده گرفته و می برد به |
86 | | `git rm -rf --cached .` | [working directory] تمامی فایل ها را از `ریپوزیرتوری لوکال` می برد به مرحله ی |
87 |
88 |
89 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-add)👈
90 |
91 | ---
92 |
93 |
94 | ##
95 | 
96 |
97 | | دستورات | توضیحات |
98 | |-----|-----:|
99 | | `git commit -m [message]` | فایل های پروژه که در مرحله ی استیجینگ قرار دارند را با یک پیغام مرتبط به مرحله ی نهایی یا هد، مخزن یا ریپوزیتوری می برد
(From staging area to HEAD or repositories) |
100 | | `git commit -am [message]` or `git commit -a -m [message]` | **فایل هایی که از قبل در پروژه ساخته شده اند** و تغییر پیدا می کنند را مستقیماً به مرحله ی ریپوزیتوری یا هد می برد
new file --> git add "file name" --> git commit -m "message"
modified file --> git commit -am "message" --> git commit -a -m "message" |
101 | | `git commit --amend -m [message]` | تغییر نام آخرین کامیت |
102 | | `git commit --amend -am [message]` or `git commit --amend -a -m [message]` | آخرین تغییرات لوکال یا ورکینگ دایرکتوری را به آخرین کامیت اضافه می کند |
103 |
104 |
105 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-rm)👈
106 |
107 | ---
108 |
109 |
110 | ##
111 | 
112 |
113 | | دستورات | توضیحات |
114 | |-----|-----:|
115 | | `git tag` or `git tag -l` | تگ برای ورژن بندی پروژه استفاده می شود که این دستور، لیست تگ های درون پروژه را نمایش می دهد و اگر تگی وجود نداشته باشد، خروجی هم نخواهیم داشت |
116 | | `git tag [tag name]` -> `git tag 3.12.0` | اگر یک ورژن یا نام بخصوصی روبروی دستور قرار دهیم آن را برای آخرین کامیت در نظر می گیرد |
117 | | `git tag 3.13.0 [commit-hash]` -> `git tag v5.2.0 6d2ef95` | با قرار دادن ورژن یا نام برای تگ بعلاوه ی کد هش کامیت مورد نظر می توانیم برای کامیت هایمان تگ بگذاریم |
118 | | `git show [tag name]` -> `git show 3.13.2` | برای مشاهده ی تغییرات درون هر تگ استفاده می کنیم |
119 | | `git tag -d [tag name]` -> `git tag -d 3.12.2` | برای حذف تگ از این دستور استفاده می کنیم |
120 | | `git tag -f [tag name] [commit-hash]` -> `git tag -f v2.1.1 6d2ef95` | ک زمانی یک تگی را اشتباهی به یک کامیت دیگر منتسب میکنیم که برای رفع این اشکال از این دستور استفاده می کنیم که می آید نام تگ را از روی کامیت قبلی برداشته و روی کامیت جدید می گذارد |
121 | | `git tag -l '13.*'` - `git tag -l '*.0'` - `git tag -l '*.1.*'` | برای سرچ در تگ ها استفاده می کنیم که در مورد اول گفته ایم تگهایی که ابتدای آنها با فلان مشخصات شروع می شود و بعد از آن هر چیزی باشد در مورد دوم گفته ایم تگ هایی را بیاور که آخر آنها صفر داشته باشد و قبل از آن هر چیزی باشد و در مورد سوم گفته ایم که تگ هایی را بیاور عدد وسط آنها یک باشد و قبل و بعد آن هر چیزی باشد |
122 |
123 |
124 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-commit)👈
125 |
126 | ---
127 |
128 |
129 |
130 |
131 | ##
132 | 
133 |
134 | | دستورات | توضیحات |
135 | |-----|-----:|
136 | | `git log` | تغییرات و کامیت های پروژه را بر می گرداند که در خروجی می توان نام و ایمیل نویسنده، تاریخ و ساعت درج کامیت را مشاهده کرد |
137 | | `git log --oneline` | تغییرات و کامیت های پروژه را به صورت **خلاصه شده و کوتاه** بر می گرداند |
138 | | `git log --oneline --all` | [origin] و [head] مشاهده ی تمامی کامیت ها و دیدن موقعیت |
139 | | `git log --stat` | تغییرات پروژه را به صورت خیلی کاملتری نمایش می دهد؛ به طوری که می توان نام و ایمیل نویسنده، تاریخ و ساعت درج کامیت و همچنین تعداد فایل های تغییر یافته و تعداد خط کدهایی که به فایل تغییر یافته اضافه یا کم شده اند را نمایش می دهد |
140 | | `git log --graph` | اطلاعات کامیت ها را به صورت **گرافیکی** نمایش می دهد |
141 | | `git log --graph --oneline` | اطلاعات کامیت ها را به صورت **گرافیکی ولی جزئی تر و خلاصه تر** برمیگرداند |
142 | | `git log --after="25-10-12"` | کامیت های **بعد از یک تاریخ مشخص** را بر میگرداند |
143 | | `git log --before="25-10-12"` | کامیت های **قبل از یک تاریخ مشخص** را بر میگرداند |
144 | | `git log --author="user-name"` | کامیت های نویسنده یا یوزر مورد نظر به همراه تاریخ و ساعت درج آنها را بر می گرداند |
145 |
146 |
147 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-tag)👈
148 |
149 | ---
150 |
151 |
152 | ##
153 | 
154 |
155 | | دستورات | توضیحات |
156 | |-----|-----:|
157 | | `git blame [file name]` | یک زمانی میخواهیم بدانیم که کدهای یک قسمت پروژه، مثلاً در یک فایل خاص، توسط چه کسی نوشته شده اند که برای این کار، از این دستور استفاده می کنیم که نام نویسنده به همراه تاریخ درج و ساعت کامیت را نمایش میدهد |
158 | | `git blame -e [file name]` | یک زمانی میخواهیم بدانیم که کدهای یک قسمت پروژه، مثلاً در یک فایل خاص، توسط چه کسی نوشته شده اند که برای این کار، از این دستور استفاده می کنیم که ایمیل نویسنده به همراه تاریخ درج و ساعت کامیت را نمایش میدهد |
159 | | `git blame [file name] -L [start-line],[end-line]` | زمانی که بخواهیم بفهمیم کدهای مثلا از خط 10 تا 20 را در فلان فایل چه کسی نوشته است از این دستور استفاده می کنیم که در خروجی، نام، تاریخ درج کامیت و ساعت آن را مشاهده خواهیم کرد |
160 | | `git blame -L start-line,end-line [file-name]` | شبیه دستور قبلیست با کمی جابجایی در دستورات |
161 |
162 |
163 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-log)👈
164 |
165 | ---
166 |
167 |
168 | ##
169 | 
170 |
171 | | دستورات | توضیحات |
172 | |-----|-----:|
173 | | `git show` | تمامی تغییرات در آخرین کامیت را برمی گرداند؛ اینکه چند خط کد اضافه یا کم شده اند یا توسط چه کسی این تغییرات اعمال شده است |
174 | | `git show [commit-hash]` | مشاهده ی تغییرات در کامیت مورد نظر با استفاده از کد هش آن کامیت |
175 | | `git show [commit-hash] --stat` | تغییرات اعمال شده در کامیت مورد نظر را به صورت خلاصه شده به همراه مشخصات نویسنده نمایش می دهد |
176 | | `git show [commit-hash] --path` | این دستور تفاوت های واقعی ایجاد شده در کامیت از جمله خطوط اضافه و حذف شده را نمایش می دهد |
177 | | `git show [tag name]` | برای مشاهده ی تغییرات درون هر تگ استفاده می کنیم |
178 |
179 |
180 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-blame)👈
181 |
182 | ---
183 |
184 |
185 | ##
186 | 
187 |
188 | | دستورات | توضیحات |
189 | |-----|-----:|
190 | | `git config --list` | لیستی از تمام تنظیمات پیکر بندی که در حال حاضر روی نسخه ی نصبی گیت شما وجود دارد را نمایش می دهد؛ مثل تنظیمات محلی، تنظیمات سراسری و تنظیمات سیستم |
191 | | `git config --local alias.[name] [command-name]` -> `git config --local alias.com commit` | با استفاده از این دستور می توانیم برای دستورات گیت درون لوکال خودمان، اسامی کوتاه تر و خلاصه انتخاب کنیم |
192 | | `git config --global alias.com commit` | اگر بخواهیم از یک نام مستعار در تمامی پروژه هایمان استفاده کنیم به جای کلمه ی لوکال از کلمه ی گلوبال استفاده میکنیم |
193 | | `git config --global user.name [your-name]` & `git config --global user.email [your-email]` | تنظیم نام کاربری و ایمیل کاربری برای تمامی پروژه ها |
194 | | `git config --global user.name` & `git config --global user.email` | مشاهده ی نام یا ایمیل کاربری که برای تمام پروژه ها انتخاب کرده ایم |
195 | | `git config user.name [your-name]` & `git config user.email [your-email]` | تنظیم نام کاربری و یا ایمیل کاربری برای یک پروژه |
196 | | `git config user.name` or `git config user.email` | مشاهده ی نام یا ایمیل کاربری که برای یک پروژه انتخاب کرده ایم |
197 |
198 |
199 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-show)👈
200 |
201 | ---
202 |
203 |
204 | ##
205 | 
206 |
207 | | دستورات | توضیحات |
208 | |-----|-----:|
209 | | `git branch` | نام برنچ ها یا شاخه های پروژه، و برنچی که درون آن قرار داریم را بر میگرداند |
210 | | `git branch -a` | لیست **تمام** برنچ ها را اعم از لوکال و ریموت بر می گرداند |
211 | | `git branch origin --delete [branch-name]` | برای حذف برنچ ریموت استفاده می شود |
212 | | `git branch [new-branch]` | ایجاد یک برنچ یا شاخه ی جدید |
213 | | `git switch [branch-name]` | سوئیچ کردن یا جابه جا شدن از یک برنچ به برنچ دیگر |
214 | | `git switch -c [new-branch-name]` | ساخت برنچ جدید و سوئیچ کردن در آن برنچ در لحظه |
215 | | `git branch -d [branch-name]` | برای حذف برنچی استفاده می شود که پس از ساخت هیچ تغییراتی درون آن صورت نگرفته و بلافاصله بخواهیم آن را حذف کنیم. اما اگر فایلی ساخته شد و کامیتی برای آن فایل در نظر گرفته شد، از دستور زیر استفاده می کنیم |
216 | | `git branch -D [branch-name]` | برای حذف شاخه یا برنچ مورد نظر استفاده می شود که در آن برنچ تغییرات و کامیت زده شده است
نباید برای حذف یک برنچ، درون خود آن برنچ باشیم؛ بلکه باید به برنچی دیگر سوئیچ کرده، سپس اقدام به حذف برنچ قبلی نماییم |
217 | | `git branch -m [new-name]` or `git branch -m [branch-name] [new-name]` | تغییر نام برنچ مورد نظر
از روش دوم زمانی استفاده می شود که در یک برنچ دیگر باشیم و بخواهیم نام یک برنچ دیگر را تغییر دهیم که دیگر نیازی به سوئیچ کردن در برنچی که میخواهیم نام آن را تغییر دهیم، نیست |
218 |
219 |
220 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-config)👈
221 |
222 | ---
223 |
224 |
225 | ##
226 | 
227 |
228 | | توضیحات | دستورات |
229 | |-----|-----:|
230 | | `git merge [feature-branch]` | الحاق برنچ فرعی به برنچ اصلی
برای مرج کردن باید در برنچ اصلی باشیم؛ و پس از اتمام عملیات باید برنچ فرعی را حذف کنیم |
231 | | `git merge [feature-branch] [main-branch]` | از این دستور زمانی استفاده می کنیم که بخواهیم بدون سوئیچ کردن به شاخه ی اصلی عملیات مرج را انجام دهیم |
232 |
233 |
234 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-branch)👈
235 |
236 | ---
237 |
238 |
239 | ##
240 | 
241 |
242 | | توضیحات | دستورات |
243 | |-----|-----:|
244 | | `git rebase [feature-branch]` | الحاق برنچ فرعی به برنچ اصلی
برای الحاق برنچ فرعی به برنچ اصلی، باید درون برنچ اصلی باشیم و سپس از این دستور استفاده کنیم |
245 | | `git rebase [feature-branch] [main-branch]` | الحاق برنچ فرعی به برنچ اصلی بدون نیاز به سوئیچ به برنچ اصلی |
246 |
247 |
248 | ### نحوه ی کار ریبیس و مرج در الحاق شاخه ها
249 |
250 |
251 | 
252 |
253 |
254 | ### مقایسه ی ریبیس و مرج
255 |
256 |
257 | | Merge | Rebase | ویژگی |
258 | |:-----:|:-----:|-----:|
259 | | ❌ | ✔️ | تغییر تاریخچه |
260 | | ✔️ | ✔️ | ادغام شاخهها |
261 | | (merge commit)✔️ | ❌ | کامیتهای اضافی |
262 | | ممکن است تاریخچه ی شاخه ها پیچیده شود ❌ | ✔️ | مرتب بودن تاریخچه |
263 | | ایمنتر ✔️ | خطرناک (نیاز به احتیاط) 🚨 | استفاده در همکاری تیمی |
264 |
265 | 🟢 زمان استفاده از Rebase: زمانی که میخواهید یک تاریخچه تمیز و بدون کامیتهای اضافی داشته باشید.
266 | 🟢زمان استفاده از Merge: زمانی که در محیط تیمی کار میکنید و نمیخواهید تاریخچه بازنویسی شود.
267 |
268 |
269 |
270 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-merge)👈
271 |
272 | ---
273 |
274 |
275 | ##
276 | 
277 |
278 | | توضیحات | دستورات |
279 | |-----|-----:|
280 | | `git stash` or `git stash save` | یک زمانی نیاز است که در برنچ فرعی یا اصلی یک سری تغییراتی ایجاد کنیم که بخواهیم بعدا آن تغییرات را به پروژه اضافه یا اعمال کنیم؛ برای این کار نیاز به یک چرک نویس یا یک جعبه یا لیست است که تغییرات را درون خود نگه داری کند تا زمانی که بخواهیم از آنها استفاده کنیم |
281 | | `git stash save [message]` | هنگام استفاده از **استش**، می توانید یک نام یا پیام برای توصیف تغییرات ذخیره شده ارائه دهید |
282 | | `git stash show` | اطلاعات کلی در مورد فایلی که استش روی آن صورت گرفته را برمی گرداند |
283 | | `git stash list` | لیست استش ها را بر می گرداند |
284 | | `git stash show stash@{index}` | نمایش تغییرات کامل هر استش با استفاده از اندیس آن |
285 | | `git stash show -p stash@{index}` | دیدن تغییرات روی استش مورد نظر با جزئیات بیشتر |
286 | | `git stash pop` | آخرین آیتم درون استش را بر می گرداند |
287 | | `git stash apply` | تغییرات **استش** انتخاب شده را به پروژه اعمال میکند بدون اینکه آن را از لیست استشها حذف کند |
288 | | `git stash drop stash@{index}` | برای حذف استش مورد نظر استفاده می شود |
289 | | `git stash clear` | حذف تمامی استش ها به صورت یکجا |
290 |
291 |
292 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-rebase)👈
293 |
294 | ---
295 |
296 |
297 | ##
298 | 
299 |
300 | | توضیحات | دستورات |
301 | |-----|-----:|
302 | | `git diff` | مشاهده یا مقایسه ی تغییرات ورکینگ دایرکتوری با استیجینگ |
303 | | `git diff --name-only [branch-name]` | مشاهده ی **نام** فایل هایی که پس از یک کامیت خاص، تغییر کرده اند |
304 | | `git diff --staged` | مشاهده یا مقایسه ی آخرین کامیت به همراه تغییرات در مرحله ی استیجینگ |
305 | | `git diff head or [HEAD]` | مقایسه ی آخرین کامیت با ورکینگ دایرکتوری |
306 | | `git diff [first-hash-commit] [second-hash-commit]` -> `git diff 28344dc 85d9a5b` or `git diff 28344dc..85d9a5b` | مشاهده یا مقایسه ی تغییرات دو کامیت با یک دیگر |
307 | | `git diff 28344dc..85d9a5b [file-name]` | مشاهده یا مقایسه ی دو کامیت در یک فایل |
308 | | `git diff [first-branch] [second-branch]` or `git diff [first-branch]..[second-branch]` | مشاهده یا مقایسه ی تغییرات دو برنچ قبل از مرج شدن با هم |
309 | | `git diff HEAD^ HEAD` | مشاهده ی تفاوت بین نسخه ی فعلی و آخرین نسخه |
310 |
311 |
312 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-stash)👈
313 |
314 | ---
315 |
316 |
317 | ##
318 | 
319 |
320 | | توضیحات | دستورات |
321 | |-----|-----:|
322 | | `git checkout [branch-name]` | به برنچی که مشخص کرده اید سوئیچ می شوید|
323 | | `git switch [branch-name]` | به برنچی که مشخص کرده اید سوئیچ می شوید |
324 | | `git checkout [hash-commit]` | زمانی که بخواهیم تغییرات پروژه را به یک کامیت در گذشته ببریم از این دستور استفاده می شود که در این صورت می گوییم **هد دیتچ یا جابجا** شده است |
325 | | `git checkout -- [file-name]` | این دستور تغییرات اعمالشده روی فایلها را در ورکینگ دایرکتوری لغو میکند و آنها را به آخرین وضعیت کامیت باز میگرداند |
326 | | `git checkout [hash-commit] [file-name]` | برگرداندن تغییرات یک فایل بخصوص به یک کامیت با هش کد آن کامیت |
327 | | `git checkout HEAD~[number]` -> `git checkout HEAD~5` | برگشتن به چند کامیت قبل تر با وارد کردن تعداد حرکت از هد به کامیت های پایین تر |
328 | | `git checkout HEAD [file-name]` | بازگرداندن تغییرات فعلی فایل، به آخرین کامیت زده شده
Discard working directory changes |
329 | | `git checkout HEAD .` | زمانی که در ورکینگ دایرکتوری روی چند فایل تغییرات ایجاد کرده ایم ولی نمی خواهیم که آن تغییرات اعمال شوند، از این دستور استفاده می کنیم که در این حالت، همه ی تغییرات را دیسکارد کرده ایم
Discarding all changes in the working directory|
330 | | `git checkout -- .` | دور انداختن همه تغییرات در ورکینگ دایرکتوری و بازگرداندن آن به وضعیت آخرین کامیت |
331 | | `git checkout -b [new-branch-name]` | ایجاد یک برنچ و سوئیچ کردن در آن |
332 |
333 |
334 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-diff)👈
335 |
336 | ---
337 |
338 |
339 | ##
340 | 
341 |
342 | | توضیحات | دستورات |
343 | |-----|-----:|
344 | | `git restore [file-name]` | زمانی که در ورکینگ دایرکتوری در یک فایلی تغییراتی ایجاد میکنیم یا به اصطلاح مادیفای می کنیم، با اجرای این دستور، تغییرات دیسکارد می شوند یا تغییرات بر می گردند به آخرین کامیت یا هد که دقیقاً کار دستور زیر را انجام می دهد
`git checkout HEAD` |
345 | | `git restore --staged [file-name]` | زمانی که یک فایل جدید ساخته ایم و به مرحله ی استیجینگ برده ایم، با اجرای این دستور به حالت **آنترکد** در می آید
`untracked` |
346 | | `git restore --source [hash-commit] [file-name] ` | این دستور شبیه دستور زیر است
git checkout [hash-commit] [file-name]
ولی با این تفاوت که، **هد** جابجا یا **دیتچ** نمی شود. یعنی داریم میگوییم که فایل مورد نظر را برگردان به فلان کد هش یا سورس مورد نظر|
347 | | `git restore --source HEAD [file-name]` | برگرداندن تغییرات به **آخرین کامیت یا هد** |
348 | | `git restore --source HEAD~5 [file-name]` | بردن **هد** به پنج کامیت قبل (تغییرات پروژه را به **5** کامیت قبل بر می گرداند) |
349 |
350 |
351 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-checkout)👈
352 |
353 | ---
354 |
355 |
356 | ##
357 | 
358 |
359 | | توضیحات | دستورات |
360 | |-----|-----:|
361 | | `git clean -h` | [clean] مشاهده ی راهنمای دستورات |
362 | | `git clean -f -d [file-name]` |حذف فایلی که ساخته شده و هنوز به مرحله ی استیجینگ نرفته و کامیتی هم برای آن در نظر گرفته نشده است |
363 |
364 |
365 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-restore)👈
366 |
367 | ---
368 |
369 |
370 | ##
371 | 
372 |
373 | | توضیحات | دستورات |
374 | |-----|-----:|
375 | | `git reset --soft [hash-commit]` | با اجرای این دستور اگر مثلاً کد هش مربوط به 4 کامیت پایینتر باشد، برمیگردیم به 4 کامیت قبل و تمامی کامیت های بالایی از ریپوزیتوری حذف می شوند اما فایل ها و تغییراتی که در پروژه صورت گرفته حذف نمی شوند بلکه به یک مرحله قبل تر یعنی استیجینگ می برد تا دوباره نسبت به آنها تصمیم گیری شود |
376 | | `git reset [hash-commit]` or `git reset --mixed [hash-commit]` | همانند دستور قبلی عمل می کند یعنی بر میگردد به کامیت قبلی و کامیت های بالایی را از ریپوزیتوری حذف می کند اما با این تفاوت که تغییرات را اگر در مرحله ی استیجینگ باشند، به مرحله ی ورکینگ دایرکتوری می برد و اگر در مرحله ی ورکینگ دایرکتوری باشند، آنها را **آنترکد** میکند |
377 | | `git reset --hard [hash-commit]` | تمام پروژه را می برد به همان کامیتی که میخواهیم و حتی مرحله ی ورکینگ دایرکتوری را هم تغییر می دهد.. یعنی تغییرات هم بر می گردند به همان کامیتی که خواسته ایم
نکته: فایل هایی که **آنترکد** بودند با اجرای این دستور از بین نمی روند چون گیت این فایلها را به دلیل **آنترکد** بودن نمی شناسد و به همین دلیل تغییری روی این فایل ها اعمال نمی شود|
378 |
379 |
380 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-clean)👈
381 |
382 | ---
383 |
384 |
385 | ##
386 | 
387 |
388 | | توضیحات | دستورات |
389 | |-----|-----:|
390 | | `git revert [hash-commit]` | از این دستور زمانی استفاده می شود که، به فرض مثال یک زمانی یک کامیتی ایجاد کرده ایم و حال متوجه می شویم که آن کامیت به درد پروژه نمی خورد؛ مثلاً میخواهیم هر کدی که قبلاً در فایل مورد نظر بوده پاک شود و کدهایی که قبلاً پاک کرده بودیم برگردند
نکته ی مهم اینکه، اگر یک کامیتی را **ریورت** کنیم که به یک کامیت دیگر وابسته باشد، به **کانفلیکت یا تداخل** میخوریم و برای حل این مشکل باید از دستور **ریست** استفاده کنیم |
391 |
392 |
393 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-reset)👈
394 |
395 | ---
396 |
397 |
398 | ##
399 | 
400 |
401 | | توضیحات | دستورات |
402 | |-----|-----:|
403 | | `git bisect start` | زمانی که تعداد کایمت های پروژه زیاد هستند و در یک جایی به باگی بر می خوریم از این دستور استفاده می کنیم تا به باگ مورد نظر رسیده و آن را فیکس کنیم؛ این دستور به صورت باینری در کامیت ها سرچ انجام می دهد تا به باگ برسد |
404 | | `git bisect good [hash-commit]` | برای استفاده از سرچ باینری در کامیت ها باید ابتدا کامیتی که در آن باگی وجود نداشت را به سرچ بدهیم و سپس سرچ را با خوب یا بد مدیریت میکنیم تا به باگ مورد نظر برسیم |
405 | | `git bisect bad` | سرچ را با خوب یا بد مدیریت می کنیم تا به باگ مورد نظر برسیم |
406 | | `git bisect reset` | پس از رسیدن به باگ مورد نظر و فیکس کردن آن، برای پایان کار از این دستور استفاده می شود |
407 |
408 |
409 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-revert)👈
410 |
411 | ---
412 |
413 |
414 | ##
415 | 
416 |
417 | | توضیحات | دستورات |
418 | |-----|-----:|
419 | | `git clone [https-repository-link]` | اضافه کردن یک کپی از یک ریپوزیتوری به لوکال ما |
420 | | `echo "# git-review" >> README.md`
`git init`
`git add README.md`
`git commit -m "first commit"`
`git branch -M main`
`git remote add origin [repository-link]`
`git push -u origin main` | زمانی که میخواهیم از ابتدا یک پروژه را آغاز کرده و به گیت و گیت هاب اضافه کنیم، این مراحل باید سپری شوند |
421 | | `git remote add origin [repository-link]`
`git branch -M main`
`git push -u origin main` | زمانی که روی پروژه کار شده و به گیت هم اضافه شده و اقامات نهایی باقی مانده است |
422 | | `git remote` | با اجرای این دستور می توان فهمید که پروژه به کدام ریموت سرویس وصل است |
423 | | `git remote -v` | اگر بخواهیم اطلاعات بیشتری در مورد ریموت داشته باشیم از این دستور استفاده می کنیم |
424 | | `git remote remove [remote-name]` | حذف ریموت مورد نظر |
425 | | `git push [remote] [branch]` | به عمل آپلود کدها ی پروژه در گیت هاب، پوش می گوییند و برای پوش کردن پروژه روی گیت هاب اسم ریموتی که انتخاب کرده ایم، و اسم برنچی که میخواهیم تغییرات آن برنچ روی ریموت مورد نظر پوش بشود را وارد می کنیم |
426 | | `git push -u origin [main-branch]` | با اجرای این دستور، ریموت و برنچ برای ما ست می شوند تا دیگر برای آپلود تغییرات روی گیت هاب نیازی به نوشتن آنها نباشد و برای بارهای بعدی فقط می توان از این دستور استفاده کرد
`git push` |
427 | | `git pull origin [main-branch]` | آوردن تغییرات از ریپوزیتوری گیت هاب به لوکال پروژه |
428 | | `git fetch [remote-name] [branch-name]` | زمانی که توسط خودمان یا همکاران در گیت هاب روی پروژه تغییراتی ایجاد شده است و میخواهیم قبل از مرج کردن آن تغییرات، مشاهده کنیم که کجاها تغییر داشته، از این دستور استفاده می شود که بعد از اجرای آن خروجی خاصی مشاهده نخواهیم کرد چون تغییرات به ریموت برنچ ما رفته است که برای دیدن آن از این دستور استفاده می کنیم
`git branch -r` |
429 | | `git branch -r` | برای مشاهده ی ریموت برنچ ها استفاده می شود |
430 | | `git switch -c [branch-name] origin/main`
or
`git checkout -b [branch-name] origin/main` | برای مشاهده ی تغییرات درون ریموت برنچ ابتدا باید یک برنچ جدید ساخت و تغییرات را در آنجا مشاهده کرد و سپس اقدام به مرج آن کنیم و در نهایت، بعد از مرج، برنچ مرج شده را حذف کنیم؛ که برای این کار، از این دستور استفاده خواهیم کرد |
431 |
432 |
433 | 👆[برو به فهرست](#go-to-the-command-list) | [قبلی](#git-bisect)👈
434 |
435 |
436 | ---
437 |
438 |
439 |
440 |
441 |
442 |
--------------------------------------------------------------------------------