clean up the git readme a bit more
This commit is contained in:
parent
8cf23b8d54
commit
275092d220
126
Git/readme.md
126
Git/readme.md
|
@ -47,6 +47,21 @@ git config --global user.name "$FISTNAME $LASTNAME"
|
|||
git config --global user.email "$EMAIL"
|
||||
```
|
||||
|
||||
Name and email are **required** configuration settings but there are a lot more settings you can change to your liking.
|
||||
For example you can set the user interface to have colors by default by setting the following configuration.
|
||||
|
||||
```bash
|
||||
git config --global color.ui auto
|
||||
```
|
||||
|
||||
All of the possible configuration settings can be seen my running:
|
||||
|
||||
```bash
|
||||
man git-config
|
||||
```
|
||||
|
||||
Additionally you can read up on all of these settings a bit more on the [documentation page](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) online.
|
||||
|
||||
## Git init
|
||||
|
||||
To initialize an existing directory as a Git repository you have to input the following command into a shell.
|
||||
|
@ -82,6 +97,38 @@ Complete directories can also be added.
|
|||
git add readme.md image.jpg
|
||||
```
|
||||
|
||||
## Git rm
|
||||
|
||||
Delete the file from project and stage the removal for commit.
|
||||
Do keep in mind that this removes the file from the next commit but the file will still exist in the previous commits.This makes it very difficult to *lose* files for ever.
|
||||
|
||||
```bash
|
||||
git rm $FILENAME
|
||||
```
|
||||
|
||||
Change an existing file path and stage the move.
|
||||
|
||||
```bash
|
||||
git mv $OLDPATH $NEWPATH
|
||||
```
|
||||
|
||||
Show all commit logs with indication of any paths that moved.
|
||||
|
||||
```bash
|
||||
git log --stat -M
|
||||
```
|
||||
|
||||
If you ever *lose* a file you can use the following command to locate when files got deleted.
|
||||
Remember that *when* is tied to a commit.
|
||||
Once you find the commit you can check out only that file to bring it back to your working directory.
|
||||
|
||||
```bash
|
||||
git log --all --full-history -- "**/$FILENAME*"
|
||||
git log --all --full-history -- $PATH_TO_FILE
|
||||
git show $SHA -- $PATH_TO_FILE
|
||||
git checkout $SHA^ -- $PATH_TO_FILE
|
||||
```
|
||||
|
||||
## Git commit
|
||||
|
||||
You commit your staged content as a new commit snapshot with the following command.
|
||||
|
@ -102,30 +149,59 @@ git commit --amend --reset-author
|
|||
## Git diff
|
||||
|
||||
Show unstaged changes between your index and working directory.
|
||||
Unstaged changes are files that have changes to them and have not been added with the *git add $FILENAME* command.
|
||||
|
||||
> $ git diff
|
||||
```bash
|
||||
git diff
|
||||
```
|
||||
|
||||
## Git log
|
||||
Show all commits in the current branch’s history
|
||||
|
||||
> $ git log
|
||||
Show all commits in the current branch’s history.
|
||||
This can be very handy, especially if the commit messages give a clean idea of *what* the commit does.
|
||||
|
||||
```bash
|
||||
git log
|
||||
```
|
||||
|
||||
More elaborate log view can be accieved with optional argument.
|
||||
Some handy ones are listed below.
|
||||
|
||||
### Graphs
|
||||
|
||||
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:
|
||||
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:
|
||||
|
||||
> $ git log --graph --oneline --decorate
|
||||
|
||||
![git log](img/git_log.PNG)
|
||||
```bash
|
||||
git log --graph --oneline --decorate
|
||||
```
|
||||
|
||||
The image below visualizes this output.
|
||||
|
||||
![git log with graph option](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
|
||||
Tig is an additional program that can be used to inspect and visualize the commit history.
|
||||
It 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.
|
||||
As it's a command line program wherein you can navigate, select, etc, we can call it a [tui](https://itsfoss.com/gui-cli-tui/).
|
||||
It comes installed by default with git in windows but on debian you have to install it manually.
|
||||
|
||||
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.
|
||||
```bash
|
||||
sudo apt install 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.
|
||||
To use tig you have to be inside a git repository and invoke the following command.
|
||||
|
||||
```bash
|
||||
tig
|
||||
```
|
||||
|
||||
![tig](img/tig.PNG)
|
||||
|
||||
#
|
||||
# SHARE & UPDATE
|
||||
#
|
||||
|
@ -184,22 +260,6 @@ merge the specified branch’s history into the current one
|
|||
show all commits in the current branch’s history
|
||||
|
||||
## TRACKING PATH CHANGES
|
||||
### Versioning file removes and path changes
|
||||
=================================
|
||||
|
||||
Delete the file from project and stage the removal for commit
|
||||
|
||||
>git rm [file]
|
||||
|
||||
Change an existing file path and stage the move
|
||||
|
||||
>git mv [existing-path] [new-path]
|
||||
|
||||
Show all commit logs with indication of any paths that moved
|
||||
|
||||
>git log --stat -M
|
||||
|
||||
|
||||
|
||||
### Checker le satus
|
||||
> git status
|
||||
|
@ -216,22 +276,6 @@ Show all commit
|
|||
Merge
|
||||
>git merge
|
||||
|
||||
# Setup
|
||||
|
||||
## Configuring user information used across all local repositories
|
||||
|
||||
>git config --global user.name “[firstname lastname]”
|
||||
|
||||
set a name that is identifiable for credit when review version history
|
||||
|
||||
>git config --global user.email “[valid-email]”
|
||||
|
||||
set an email address that will be associated with each history marker
|
||||
|
||||
>git config --global color.ui auto
|
||||
|
||||
set automatic command line coloring for Git for easy reviewing
|
||||
|
||||
## Saving your uncommitted work for a quick fix then getting it back
|
||||
|
||||
>git stash
|
||||
|
|
Loading…
Reference in New Issue