rewriting basic command chapter

This commit is contained in:
vl4dd 2021-04-03 12:17:49 +02:00
parent 30c1bd1666
commit 1a1de5ded6
1 changed files with 69 additions and 92 deletions

View File

@ -1,101 +1,98 @@
# Git # Git
## Description
![GitHub Logo](img/image.jpg) Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
## Usefull links ## Usefull links
[Git Cheat Sheet](https://education.github.com/git-cheat-sheet-education.pdf) - [Git Cheat Sheet](https://education.github.com/git-cheat-sheet-education.pdf)
## Git System ## Git System
![Git System](img/Git_Guide.png) <img src="img/Git_Guide.png" width=604 height=370>
=
## Remote Execution # Basic commands
![Remote Execution](img/Remote_execution.png)
## Git clone
#
Clone repo located at **\<repo>** onto local machine. Original repo can be located on the local filesystem or on a remote machine via **HTTPS** or **SSH**.
## Basic commands > git clone <repo>
=================
### Initialize an existing directory as a Git repository ## Git init
```bash #
$ git init Initialize an existing directory as a Git repository
Initialized empty Git repository in C:/Users/Admin/Documents/Git/.git/ > git init
```
### Show modified files in working directory, staged for your next commit
```bash Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
$ git status
On branch master
No commits yet > $ git init \<directory>
=
Untracked files: ## Git status
(use "git add <file>..." to include in what will be committed) #
Readme.md List which files are staged, unstaged, and untracked.
image.jpg
nothing added to commit but untracked files present (use "git add" to track) > $ git status
```
### Add a file as it looks now to your next commit (stage)
```bash
$ git add Readme.md image.jpg
```
### Commit your staged content as a new commit snapshot
```bash
$ git commit -m "First Commit"
[master (root-commit) 784ae2e] First Commit
Committer: unknown <Admin@FOR209-03.irisib.lan>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name" ## Git config --global name & email
git config --global user.email you@example.com #
Must be identifiable for credit when review version history.
> $ git config --global user.name “[firstname lastname]”
> $ git config --global user.email “[valid-email]”
## Git add
#
Stage all changes in **\<directory>** for the next commit. Replace **\<directory>** with a **\<file>** to change a specific file.
> $ git add readme.md image.jpg
## Git commit
#
Commit your staged content as a new commit snapshot
> $ git commit -m "First Commit"
After doing this, you may fix the identity used for this commit with: After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author > $ git commit --amend --reset-author
2 files changed, 61 insertions(+)
create mode 100644 Readme.md
create mode 100644 image.jpg
```
### Set a name & email that is identifiable for credit when review version history ## Git log
```bash #
$ git config --global user.name “[firstname lastname]” Show all commits in the current branchs history
$ git config --global user.email “[valid-email]” > $ git log
```
### Show all commits in the current branchs history ### Graphs
```bash
$ git log
commit 784ae2e2d10720c23eb7cebdf8386ef2157fe628 (HEAD -> master)
Author: unknown <Admin@FOR209-03.irisib.lan>
Date: Thu Apr 1 12:11:34 2021 +0200
First Commit The --graph option draws an ASCII graph representing the branch structure of the commit history. This is commonly used in conjunction with the --oneline and --decorate commands to make it easier to see which commit belongs to which branch:
```
### tig vs git log --graph > $ git log --graph --oneline --decorate
![git log](img/git_log.PNG)
=
## Tig
#
Tig allows you to browse changes in a Git repository and can additionally act as a pager for output of various Git commands. When used as a pager, it will display input from stdin and colorize it. Tig allows you to browse changes in a Git repository and can additionally act as a pager for output of various Git commands. When used as a pager, it will display input from stdin and colorize it.
When browsing repositories, Tig uses the underlying Git commands to present the user with various views, such as summarized commit log and showing the commit with the log message, diffstat, and the diff.
> $ tig > $ tig
## tig When browsing repositories, Tig uses the underlying Git commands to present the user with various views, such as summarized commit log and showing the commit with the log message, diffstat, and the diff.
![tig](img/tig.PNG) ![tig](img/tig.PNG)
=
> $ git log --graph ## Git diff
#
Show unstaged changes between your index and working directory.
## git log > $ git diff
![git log](img/git_log.PNG)
#
## SHARE & UPDATE # SHARE & UPDATE
#
### Retrieving updates from another repository and updating local repos ### Retrieving updates from another repository and updating local repos
================================= =================================
@ -119,7 +116,6 @@ Transmit local branch commits to the remote repository branch
fetch and merge any commits from the tracking remote branch fetch and merge any commits from the tracking remote branch
## BRANCH & MERGE ## BRANCH & MERGE
### Isolating work in branches, changing context, and integrating changes ### Isolating work in branches, changing context, and integrating changes
@ -168,27 +164,8 @@ Show all commit logs with indication of any paths that moved
>git log --stat -M >git log --stat -M
### History
```bash
history
1 git init
2 git status
3 git add Readme.md image.jpg
4 git status
5 git commit -m "First Commit"
6 git config --global user.name vl4dd
7 git config --global user.email ticus@kraland.net
8 git commit -m "First Commit"
9 git status
10 git log
11 git commit -m "Second commit"
12 git add Readme.md
13 git commit -m "Second commit"
14 git log
```
### ### Checker le satus
Checker le satus
> git status > git status
Ajouter un element dans la branche Ajouter un element dans la branche
@ -203,9 +180,9 @@ Show all commit
Merge Merge
>git merge >git merge
## Setup # Setup
### Configuring user information used across all local repositories ## Configuring user information used across all local repositories
>git config --global user.name “[firstname lastname]” >git config --global user.name “[firstname lastname]”
@ -219,7 +196,7 @@ set an email address that will be associated with each history marker
set automatic command line coloring for Git for easy reviewing set automatic command line coloring for Git for easy reviewing
### Saving your uncommitted work for a quick fix then getting it back ## Saving your uncommitted work for a quick fix then getting it back
>git stash >git stash
@ -233,7 +210,7 @@ $ git stash pop stash@{2}
in case you want to apply a specific Stash item (not the most recent one), you can provide the index name of that item in the "pop" option in case you want to apply a specific Stash item (not the most recent one), you can provide the index name of that item in the "pop" option
### Rewriting history ## Rewriting history
>git commit --amend -m "New commit message" >git commit --amend -m "New commit message"
@ -247,7 +224,7 @@ replace the last commit without changing the commit message
take the precedent commit and add it to your branch take the precedent commit and add it to your branch
### Ignoring files ## Ignoring files
>touch .gitignore && echo {what you want to ignore} >> .gitignore >touch .gitignore && echo {what you want to ignore} >> .gitignore