| ... | @@ -5,14 +5,14 @@ Git is a versionning tool allowing multiple programmers to work simultaneously o |
... | @@ -5,14 +5,14 @@ Git is a versionning tool allowing multiple programmers to work simultaneously o |
|
|
# commands
|
|
# commands
|
|
|
## add
|
|
## add
|
|
|
|
|
|
|
|
To prepare a [commit](#commit) : each added file will be in your next (commit)[Get good at git#commit]
|
|
To prepare a [commit](#commit) : each added file will be in your next [commit](#commit)
|
|
|
```bash
|
|
```bash
|
|
|
git add <file/folder>
|
|
git add <file/folder>
|
|
|
```
|
|
```
|
|
|
To remove an added file use the (restore --staged <path>)[#args] command .
|
|
To remove an added file use the (restore --staged <path>)[#args] command .
|
|
|
|
|
|
|
|
## bisect
|
|
## bisect
|
|
|
allow you to research when a bug has occurred within your history : if a commit is good or bad.
|
|
allow you to research when a bug has occurred within your history : if a [commit](#commit) is good or bad.
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
git bisect start
|
|
git bisect start
|
| ... | @@ -22,15 +22,12 @@ git bisect good |
... | @@ -22,15 +22,12 @@ git bisect good |
|
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## branch
|
|
## branch
|
|
|
To handle git branches, be it renaming, copy, deletion.
|
|
To handle git branches, be it listing, renaming, copying, deletion.
|
|
|
|
|
|
|
|
## cherry-pick
|
|
Shows repo branches:
|
|
|
Re-apply a given commit on the current branch. Useful when you want a feature from another branch without merging everything.
|
|
|
|
|
```bash
|
|
```bash
|
|
|
git cherry-pick <commit_hash>
|
|
git branch
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
#### -m / --move
|
|
#### -m / --move
|
| ... | @@ -45,7 +42,12 @@ will output your current git branch |
... | @@ -45,7 +42,12 @@ will output your current git branch |
|
|
git branch --show-current
|
|
git branch --show-current
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
---
|
|
## cherry-pick
|
|
|
|
Re-apply a given commit on the current branch. Useful when you want a feature from another branch without merging everything.
|
|
|
|
```bash
|
|
|
|
git cherry-pick <commit_hash>
|
|
|
|
```
|
|
|
|
|
|
|
## clone
|
|
## clone
|
|
|
clone a repository
|
|
clone a repository
|
|
|
```bash
|
|
```bash
|
| ... | @@ -53,13 +55,8 @@ git clone <repository> [<dest_dir>] |
... | @@ -53,13 +55,8 @@ git clone <repository> [<dest_dir>] |
|
|
```
|
|
```
|
|
|
repository is either ssh or https address of the repo.
|
|
repository is either ssh or https address of the repo.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
## commit
|
|
## commit
|
|
|
A commit is like a checkpoint : you have modified multiple files, and you [[#push]] them to the [[#origin]] with a commit message like "hey I've done this and that".
|
|
A commit is like a checkpoint : you have modified multiple files, and you [push](#push) them to the [origin](#origin) with a commit message like "hey I've done this and that".
|
|
|
|
|
|
|
|
A commit can but doesn't have to contain all your modified files, it will only include (added)[[#add|]] files.
|
|
A commit can but doesn't have to contain all your modified files, it will only include (added)[[#add|]] files.
|
|
|
any commit will be accompanied by a **commit message** that NEEDS to contain the important things that has been modified in the added files.
|
|
any commit will be accompanied by a **commit message** that NEEDS to contain the important things that has been modified in the added files.
|
| ... | @@ -75,6 +72,7 @@ shows you differences between current branch and given branch. |
... | @@ -75,6 +72,7 @@ shows you differences between current branch and given branch. |
|
|
git diff
|
|
git diff
|
|
|
```
|
|
```
|
|
|
will show you differences between your local branch and `origin`.
|
|
will show you differences between your local branch and `origin`.
|
|
|
|
|
|
|
### args
|
|
### args
|
|
|
#### `- p <commit>`
|
|
#### `- p <commit>`
|
|
|
Will show differences between current branch and given `<COMMIT>`
|
|
Will show differences between current branch and given `<COMMIT>`
|
| ... | @@ -84,8 +82,6 @@ git diff -p <COMMIT> |
... | @@ -84,8 +82,6 @@ git diff -p <COMMIT> |
|
|
#### `--compact-summary`
|
|
#### `--compact-summary`
|
|
|
Show a short summary of modifications file-by-file before going in-depth
|
|
Show a short summary of modifications file-by-file before going in-depth
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## log
|
|
## log
|
|
|
shows commit history of the current repo.
|
|
shows commit history of the current repo.
|
|
|
|
|
|
| ... | @@ -96,7 +92,10 @@ git log -S<keyword> |
... | @@ -96,7 +92,10 @@ git log -S<keyword> |
|
|
search for `keyword` in commits modifications to show you when it was modified, very useful to know when a function was removed for example.
|
|
search for `keyword` in commits modifications to show you when it was modified, very useful to know when a function was removed for example.
|
|
|
|
|
|
|
|
#### `-n`
|
|
#### `-n`
|
|
|
retrieves the n last commits
|
|
retrieves the n last commits (here the last 10)
|
|
|
|
```bash
|
|
|
|
git log -10
|
|
|
|
```
|
|
|
|
|
|
|
|
#### `--format=`
|
|
#### `--format=`
|
|
|
retrieves only a part of the commit, either date, hash or message.
|
|
retrieves only a part of the commit, either date, hash or message.
|
| ... | @@ -166,8 +165,6 @@ git rebase -i --autosquash <hash> |
... | @@ -166,8 +165,6 @@ git rebase -i --autosquash <hash> |
|
|
#### `--fixup`
|
|
#### `--fixup`
|
|
|
same as above but with the fixup command
|
|
same as above but with the fixup command
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## merge
|
|
## merge
|
|
|
Action of bringing modifications of modifications brought in a branch to another branch.
|
|
Action of bringing modifications of modifications brought in a branch to another branch.
|
|
|
|
|
|
| ... | @@ -239,7 +236,7 @@ git remote remove <remote_name> |
... | @@ -239,7 +236,7 @@ git remote remove <remote_name> |
|
|
---
|
|
---
|
|
|
## restore
|
|
## restore
|
|
|
Undoes all modifications done to given file/folder/path done since last commit
|
|
Undoes all modifications done to given file/folder/path done since last commit
|
|
|
> [!warning] This command cannot be undone
|
|
> :warning: This command cannot be undone
|
|
|
> If you git restored files that contained valuable modifications you will have to redo it by hand.
|
|
> If you git restored files that contained valuable modifications you will have to redo it by hand.
|
|
|
```bash
|
|
```bash
|
|
|
git restore <file/folder/path>
|
|
git restore <file/folder/path>
|
| ... | @@ -250,12 +247,12 @@ git restore <file/folder/path> |
... | @@ -250,12 +247,12 @@ git restore <file/folder/path> |
|
|
```bash
|
|
```bash
|
|
|
restore --staged <path>
|
|
restore --staged <path>
|
|
|
```
|
|
```
|
|
|
will remove given file of the list of (added)[[#add|]] files.
|
|
will remove given file of the list of (added)[#add] files.
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
|
|
## revert
|
|
## revert
|
|
|
Reverts the modifications of a specific commit, often paired with [[#Cherry pick]].
|
|
Reverts the modifications of a specific commit, often paired with [cherry pick](#Cherry pick).
|
|
|
```bash
|
|
```bash
|
|
|
git revert <commit_hash>
|
|
git revert <commit_hash>
|
|
|
```
|
|
```
|
| ... | @@ -286,7 +283,7 @@ Once you have set up your repo in local you can start modifying it. |
... | @@ -286,7 +283,7 @@ Once you have set up your repo in local you can start modifying it. |
|
|
```bash
|
|
```bash
|
|
|
git status
|
|
git status
|
|
|
```
|
|
```
|
|
|
will show you what files you have modified / (added)[[#add|]] and not (commited)[[#commit|]].
|
|
will show you what files you have modified / [added](#add) and not [commited](#commit).
|
|
|
|
|
|
|
|
### save
|
|
### save
|
|
|
allows you to give a specific name to the stash you are creating :
|
|
allows you to give a specific name to the stash you are creating :
|
| ... | @@ -321,17 +318,14 @@ To show how files are modified by a given stash : |
... | @@ -321,17 +318,14 @@ To show how files are modified by a given stash : |
|
|
git stash show -p
|
|
git stash show -p
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
## switch
|
|
## switch
|
|
|
change current active branch
|
|
change current active branch
|
|
|
```bash
|
|
```bash
|
|
|
git switch <branch>
|
|
git switch <branch>
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## checkout
|
|
## checkout
|
|
|
Like [[#switch]] but not on a [[#commit]], allow you to modify and apply modification on chosen branch afterward
|
|
Like [switch](switch) but not on a [commit](#commit)], allow you to modify and apply modification on chosen branch afterward
|
|
|
```bash
|
|
```bash
|
|
|
git checkout <commit_hash>
|
|
git checkout <commit_hash>
|
|
|
```
|
|
```
|
| ... | @@ -352,7 +346,7 @@ git revert <COMMIT_HASH> |
... | @@ -352,7 +346,7 @@ git revert <COMMIT_HASH> |
|
|
|
|
|
|
|
> [!danger] ⚠ VERY DANGEROUS ⚠
|
|
> [!danger] ⚠ VERY DANGEROUS ⚠
|
|
|
> The following command DESTROYS EVERY COMMITS PUSHED SINCE THE ONE YOU WANT TO DELETE
|
|
> The following command DESTROYS EVERY COMMITS PUSHED SINCE THE ONE YOU WANT TO DELETE
|
|
|
> - always prefer the [[#revert]] command.
|
|
> - always prefer the [revert](#revert) command.
|
|
|
> - NEVER do it on `main` branch
|
|
> - NEVER do it on `main` branch
|
|
|
> - ALWAYS
|
|
> - ALWAYS
|
|
|
> - triple check your commit hash before calling `git push -f`
|
|
> - triple check your commit hash before calling `git push -f`
|
| ... | @@ -367,7 +361,7 @@ git push -f |
... | @@ -367,7 +361,7 @@ git push -f |
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Re-apply a `commit`
|
|
## Re-apply a `commit`
|
|
|
![[git🌳#cherry-pick]]
|
|
[git cherry-pick](#cherry-pick)
|
|
|
|
|
|
|
|
## undo an unpushed commit
|
|
## undo an unpushed commit
|
|
|
```bash
|
|
```bash
|
| ... | @@ -393,7 +387,7 @@ git -C <path_to_repo> <git_command> |
... | @@ -393,7 +387,7 @@ git -C <path_to_repo> <git_command> |
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Change the author of a commit
|
|
## Change the author of a commit
|
|
|
Use (git rebase)[[#rebase|]] for that
|
|
Use [git rebase](#rebase) for that
|
|
|
```bash
|
|
```bash
|
|
|
git rebase -i <hash>
|
|
git rebase -i <hash>
|
|
|
```
|
|
```
|
| ... | | ... | |