mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 07:43:24 +03:00
Merge pull request #1359 from ayush--s/gitedit
[git/en] added gitignore section plus few other things
This commit is contained in:
commit
da378ae56e
@ -18,7 +18,7 @@ manage your source code.
|
||||
|
||||
### What is version control?
|
||||
|
||||
Version control is a system that records changes to a file, or set of files, over time.
|
||||
Version control is a system that records changes to a file(s), over time.
|
||||
|
||||
### Centralized Versioning VS Distributed Versioning
|
||||
|
||||
@ -42,8 +42,9 @@ Version control is a system that records changes to a file, or set of files, ove
|
||||
|
||||
### Repository
|
||||
|
||||
A set of files, directories, historical records, commits, and heads. Imagine it as a source code data structure,
|
||||
with the attribute that each source code "element" gives you access to its revision history, among other things.
|
||||
A set of files, directories, historical records, commits, and heads. Imagine it
|
||||
as a source code data structure, with the attribute that each source code
|
||||
"element" gives you access to its revision history, among other things.
|
||||
|
||||
A git repository is comprised of the .git directory & working tree.
|
||||
|
||||
@ -54,32 +55,33 @@ The .git directory contains all the configurations, logs, branches, HEAD, and mo
|
||||
|
||||
### Working Tree (component of repository)
|
||||
|
||||
This is basically the directories and files in your repository. It is often referred to
|
||||
as your working directory.
|
||||
This is basically the directories and files in your repository. It is often
|
||||
referred to as your working directory.
|
||||
|
||||
### Index (component of .git dir)
|
||||
|
||||
The Index is the staging area in git. It's basically a layer that separates your working tree
|
||||
from the Git repository. This gives developers more power over what gets sent to the Git
|
||||
repository.
|
||||
from the Git repository. This gives developers more power over what gets sent
|
||||
to the Git repository.
|
||||
|
||||
### Commit
|
||||
|
||||
A git commit is a snapshot of a set of changes, or manipulations to your Working Tree.
|
||||
For example, if you added 5 files, and removed 2 others, these changes will be contained
|
||||
in a commit (or snapshot). This commit can then be pushed to other repositories, or not!
|
||||
A git commit is a snapshot of a set of changes, or manipulations to your Working
|
||||
Tree. For example, if you added 5 files, and removed 2 others, these changes
|
||||
will be contained in a commit (or snapshot). This commit can then be pushed to
|
||||
other repositories, or not!
|
||||
|
||||
### Branch
|
||||
|
||||
A branch is essentially a pointer that points to the last commit you made. As you commit,
|
||||
this pointer will automatically update and point to the latest commit.
|
||||
A branch is essentially a pointer to the last commit you made. As you go on
|
||||
committing, this pointer will automatically update to point the latest commit.
|
||||
|
||||
### HEAD and head (component of .git dir)
|
||||
|
||||
HEAD is a pointer that points to the current branch. A repository only has 1 *active* HEAD.
|
||||
head is a pointer that points to any commit. A repository can have any number of heads.
|
||||
|
||||
###Stages of Git
|
||||
### Stages of Git
|
||||
* Modified - Changes have been made to a file but file has not been committed to Git Database yet
|
||||
* Staged - Marks a modified file to go into your next commit snapshot
|
||||
* Committed - Files have been committed to the Git Database
|
||||
@ -104,15 +106,12 @@ $ git init
|
||||
|
||||
### config
|
||||
|
||||
To configure settings. Whether it be for the repository, the system itself, or global
|
||||
configurations.
|
||||
To configure settings. Whether it be for the repository, the system itself,
|
||||
or global configurations ( global config file is `~/.gitconfig` ).
|
||||
|
||||
|
||||
```bash
|
||||
# Print & Set Some Basic Config Variables (Global)
|
||||
$ git config --global user.email
|
||||
$ git config --global user.name
|
||||
|
||||
$ git config --global user.email "MyEmail@Zoho.com"
|
||||
$ git config --global user.name "My Name"
|
||||
```
|
||||
@ -142,10 +141,20 @@ $ git commit --help
|
||||
$ git init --help
|
||||
```
|
||||
|
||||
### ignore files
|
||||
|
||||
To intentionally untrack file(s) & folder(s) from git. Typically meant for
|
||||
private & temp files which would otherwise be shared in the repository.
|
||||
```bash
|
||||
$ echo "temp/" >> .gitignore
|
||||
$ echo "private_key" >> .gitignore
|
||||
```
|
||||
|
||||
|
||||
### status
|
||||
|
||||
To show differences between the index file (basically your working copy/repo) and the current
|
||||
HEAD commit.
|
||||
To show differences between the index file (basically your working copy/repo)
|
||||
and the current HEAD commit.
|
||||
|
||||
|
||||
```bash
|
||||
@ -172,7 +181,8 @@ $ git add /path/to/file/HelloWorld.c
|
||||
$ git add ./*.java
|
||||
```
|
||||
|
||||
This only adds a file to the staging area/index, it doesn't commit it to the working directory/repo.
|
||||
This only adds a file to the staging area/index, it doesn't commit it to the
|
||||
working directory/repo.
|
||||
|
||||
### branch
|
||||
|
||||
@ -205,7 +215,8 @@ Updates all files in the working tree to match the version in the index, or spec
|
||||
$ git checkout
|
||||
# Checkout a specified branch
|
||||
$ git checkout branchName
|
||||
# Create a new branch & switch to it, like: "git branch <name>; git checkout <name>"
|
||||
# Create a new branch & switch to it
|
||||
# equivalent to "git branch <name>; git checkout <name>"
|
||||
$ git checkout -b newBranch
|
||||
```
|
||||
|
||||
@ -218,6 +229,10 @@ to a remote branch.
|
||||
```bash
|
||||
# Clone learnxinyminutes-docs
|
||||
$ git clone https://github.com/adambard/learnxinyminutes-docs.git
|
||||
# shallow clone - faster cloning that pulls only latest snapshot
|
||||
$ git clone --depth 1 https://github.com/adambard/learnxinyminutes-docs.git
|
||||
# clone only a specific branch
|
||||
$ git clone -b master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch
|
||||
```
|
||||
|
||||
### commit
|
||||
@ -231,6 +246,9 @@ $ git commit -m "Added multiplyNumbers() function to HelloWorld.c"
|
||||
|
||||
# automatically stage modified or deleted files, except new files, and then commit
|
||||
$ git commit -a -m "Modified foo.php and removed bar.php"
|
||||
|
||||
# change last commit (this deletes previous commit with a fresh commit)
|
||||
$ git commit --amend -m "Correct message"
|
||||
```
|
||||
|
||||
### diff
|
||||
@ -282,8 +300,8 @@ Display commits to the repository.
|
||||
# Show all commits
|
||||
$ git log
|
||||
|
||||
# Show X number of commits
|
||||
$ git log -n 10
|
||||
# Show only commit message & ref
|
||||
$ git log --oneline
|
||||
|
||||
# Show merge commits only
|
||||
$ git log --merges
|
||||
@ -352,11 +370,13 @@ $ git push
|
||||
|
||||
### stash
|
||||
|
||||
Stashing takes the dirty state of your working directory and saves it on a stack of unfinished changes that you can reapply at any time.
|
||||
Stashing takes the dirty state of your working directory and saves it on a stack
|
||||
of unfinished changes that you can reapply at any time.
|
||||
|
||||
Let's say you've been doing some work in your git repo, but you want to pull from the remote.
|
||||
Since you have dirty (uncommited) changes to some files, you are not able to run `git pull`.
|
||||
Instead, you can run `git stash` to save your changes onto a stack!
|
||||
Let's say you've been doing some work in your git repo, but you want to pull
|
||||
from the remote. Since you have dirty (uncommited) changes to some files, you
|
||||
are not able to run `git pull`. Instead, you can run `git stash` to save your
|
||||
changes onto a stack!
|
||||
|
||||
```bash
|
||||
$ git stash
|
||||
|
Loading…
Reference in New Issue
Block a user