mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
fixed whitespaces, content extending beyond 80 chars
This commit is contained in:
parent
2f3597efc4
commit
01bf2b1ec6
@ -24,9 +24,12 @@ Version control is a system that records changes to a file(s), over time.
|
|||||||
|
|
||||||
### Centralized Versioning VS Distributed Versioning
|
### Centralized Versioning VS Distributed Versioning
|
||||||
|
|
||||||
* Centralized version control focuses on synchronizing, tracking, and backing up files.
|
* Centralized version control focuses on synchronizing, tracking, and backing
|
||||||
* Distributed version control focuses on sharing changes. Every change has a unique id.
|
up files.
|
||||||
* Distributed systems have no defined structure. You could easily have a SVN style, centralized system, with git.
|
* Distributed version control focuses on sharing changes. Every change has a
|
||||||
|
unique id.
|
||||||
|
* Distributed systems have no defined structure. You could easily have a SVN
|
||||||
|
style, centralized system, with git.
|
||||||
|
|
||||||
[Additional Information](http://git-scm.com/book/en/Getting-Started-About-Version-Control)
|
[Additional Information](http://git-scm.com/book/en/Getting-Started-About-Version-Control)
|
||||||
|
|
||||||
@ -42,7 +45,6 @@ Version control is a system that records changes to a file(s), over time.
|
|||||||
|
|
||||||
## Git Architecture
|
## Git Architecture
|
||||||
|
|
||||||
|
|
||||||
### Repository
|
### Repository
|
||||||
|
|
||||||
A set of files, directories, historical records, commits, and heads. Imagine it
|
A set of files, directories, historical records, commits, and heads. Imagine it
|
||||||
@ -53,7 +55,8 @@ A git repository is comprised of the .git directory & working tree.
|
|||||||
|
|
||||||
### .git Directory (component of repository)
|
### .git Directory (component of repository)
|
||||||
|
|
||||||
The .git directory contains all the configurations, logs, branches, HEAD, and more.
|
The .git directory contains all the configurations, logs, branches, HEAD, and
|
||||||
|
more.
|
||||||
[Detailed List.](http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html)
|
[Detailed List.](http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html)
|
||||||
|
|
||||||
### Working Tree (component of repository)
|
### Working Tree (component of repository)
|
||||||
@ -63,16 +66,16 @@ referred to as your working directory.
|
|||||||
|
|
||||||
### Index (component of .git dir)
|
### Index (component of .git dir)
|
||||||
|
|
||||||
The Index is the staging area in git. It's basically a layer that separates your working tree
|
The Index is the staging area in git. It's basically a layer that separates
|
||||||
from the Git repository. This gives developers more power over what gets sent
|
your working tree from the Git repository. This gives developers more power
|
||||||
to the Git repository.
|
over what gets sent to the Git repository.
|
||||||
|
|
||||||
### Commit
|
### Commit
|
||||||
|
|
||||||
A git commit is a snapshot of a set of changes, or manipulations to your Working
|
A git commit is a snapshot of a set of changes, or manipulations to your
|
||||||
Tree. For example, if you added 5 files, and removed 2 others, these changes
|
Working Tree. For example, if you added 5 files, and removed 2 others, these
|
||||||
will be contained in a commit (or snapshot). This commit can then be pushed to
|
changes will be contained in a commit (or snapshot). This commit can then be
|
||||||
other repositories, or not!
|
pushed to other repositories, or not!
|
||||||
|
|
||||||
### Branch
|
### Branch
|
||||||
|
|
||||||
@ -86,11 +89,14 @@ functionality to mark release points (v1.0, and so on)
|
|||||||
|
|
||||||
### HEAD and head (component of .git dir)
|
### 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 the current branch. A repository only has 1
|
||||||
head is a pointer that points to any commit. A repository can have any number of heads.
|
*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
|
* 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
|
* Staged - Marks a modified file to go into your next commit snapshot
|
||||||
* Committed - Files have been committed to the Git Database
|
* Committed - Files have been committed to the Git Database
|
||||||
|
|
||||||
@ -99,14 +105,12 @@ head is a pointer that points to any commit. A repository can have any number of
|
|||||||
* [Git For Computer Scientists](http://eagain.net/articles/git-for-computer-scientists/)
|
* [Git For Computer Scientists](http://eagain.net/articles/git-for-computer-scientists/)
|
||||||
* [Git For Designers](http://hoth.entp.com/output/git_for_designers.html)
|
* [Git For Designers](http://hoth.entp.com/output/git_for_designers.html)
|
||||||
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
|
|
||||||
### init
|
### init
|
||||||
|
|
||||||
Create an empty Git repository. The Git repository's settings, stored information,
|
Create an empty Git repository. The Git repository's settings, stored
|
||||||
and more is stored in a directory (a folder) named ".git".
|
information, and more is stored in a directory (a folder) named ".git".
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git init
|
$ git init
|
||||||
@ -117,7 +121,6 @@ $ git init
|
|||||||
To configure settings. Whether it be for the repository, the system itself,
|
To configure settings. Whether it be for the repository, the system itself,
|
||||||
or global configurations ( global config file is `~/.gitconfig` ).
|
or global configurations ( global config file is `~/.gitconfig` ).
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Print & Set Some Basic Config Variables (Global)
|
# Print & Set Some Basic Config Variables (Global)
|
||||||
$ git config --global user.email "MyEmail@Zoho.com"
|
$ git config --global user.email "MyEmail@Zoho.com"
|
||||||
@ -158,13 +161,11 @@ $ echo "temp/" >> .gitignore
|
|||||||
$ echo "private_key" >> .gitignore
|
$ echo "private_key" >> .gitignore
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### status
|
### status
|
||||||
|
|
||||||
To show differences between the index file (basically your working copy/repo)
|
To show differences between the index file (basically your working copy/repo)
|
||||||
and the current HEAD commit.
|
and the current HEAD commit.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Will display the branch, untracked files, changes and other differences
|
# Will display the branch, untracked files, changes and other differences
|
||||||
$ git status
|
$ git status
|
||||||
@ -175,8 +176,8 @@ $ git help status
|
|||||||
|
|
||||||
### add
|
### add
|
||||||
|
|
||||||
To add files to the staging area/index. If you do not `git add` new files to the
|
To add files to the staging area/index. If you do not `git add` new files to
|
||||||
staging area/index, they will not be included in commits!
|
the staging area/index, they will not be included in commits!
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# add a file in your current working directory
|
# add a file in your current working directory
|
||||||
@ -194,7 +195,8 @@ working directory/repo.
|
|||||||
|
|
||||||
### branch
|
### branch
|
||||||
|
|
||||||
Manage your branches. You can view, edit, create, delete branches using this command.
|
Manage your branches. You can view, edit, create, delete branches using this
|
||||||
|
command.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# list existing branches & remotes
|
# list existing branches & remotes
|
||||||
@ -221,54 +223,64 @@ Manage your tags
|
|||||||
```bash
|
```bash
|
||||||
# List tags
|
# List tags
|
||||||
$ git tag
|
$ git tag
|
||||||
|
|
||||||
# Create a annotated tag
|
# Create a annotated tag
|
||||||
# The -m specifies a tagging message,which is stored with the tag.
|
# The -m specifies a tagging message,which is stored with the tag.
|
||||||
# If you don’t specify a message for an annotated tag,
|
# If you don’t specify a message for an annotated tag,
|
||||||
# Git launches your editor so you can type it in.
|
# Git launches your editor so you can type it in.
|
||||||
$ git tag -a v2.0 -m 'my version 2.0'
|
$ git tag -a v2.0 -m 'my version 2.0'
|
||||||
|
|
||||||
# Show info about tag
|
# Show info about tag
|
||||||
# That shows the tagger information, the date the commit was tagged,
|
# That shows the tagger information, the date the commit was tagged,
|
||||||
# and the annotation message before showing the commit information.
|
# and the annotation message before showing the commit information.
|
||||||
$ git show v2.0
|
$ git show v2.0
|
||||||
|
|
||||||
# Push a single tag to remote
|
# Push a single tag to remote
|
||||||
$ git push origin v2.0
|
$ git push origin v2.0
|
||||||
|
|
||||||
# Push a lot of tags to remote
|
# Push a lot of tags to remote
|
||||||
$ git push origin --tags
|
$ git push origin --tags
|
||||||
```
|
```
|
||||||
|
|
||||||
### checkout
|
### checkout
|
||||||
|
|
||||||
Updates all files in the working tree to match the version in the index, or specified tree.
|
Updates all files in the working tree to match the version in the index, or
|
||||||
|
specified tree.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Checkout a repo - defaults to master branch
|
# Checkout a repo - defaults to master branch
|
||||||
$ git checkout
|
$ git checkout
|
||||||
|
|
||||||
# Checkout a specified branch
|
# Checkout a specified branch
|
||||||
$ git checkout branchName
|
$ git checkout branchName
|
||||||
|
|
||||||
# Create a new branch & switch to it
|
# Create a new branch & switch to it
|
||||||
# equivalent to "git branch <name>; git checkout <name>"
|
# equivalent to "git branch <name>; git checkout <name>"
|
||||||
|
|
||||||
$ git checkout -b newBranch
|
$ git checkout -b newBranch
|
||||||
```
|
```
|
||||||
|
|
||||||
### clone
|
### clone
|
||||||
|
|
||||||
Clones, or copies, an existing repository into a new directory. It also adds
|
Clones, or copies, an existing repository into a new directory. It also adds
|
||||||
remote-tracking branches for each branch in the cloned repo, which allows you to push
|
remote-tracking branches for each branch in the cloned repo, which allows you
|
||||||
to a remote branch.
|
to push to a remote branch.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Clone learnxinyminutes-docs
|
# Clone learnxinyminutes-docs
|
||||||
$ git clone https://github.com/adambard/learnxinyminutes-docs.git
|
$ git clone https://github.com/adambard/learnxinyminutes-docs.git
|
||||||
|
|
||||||
# shallow clone - faster cloning that pulls only latest snapshot
|
# shallow clone - faster cloning that pulls only latest snapshot
|
||||||
$ git clone --depth 1 https://github.com/adambard/learnxinyminutes-docs.git
|
$ git clone --depth 1 https://github.com/adambard/learnxinyminutes-docs.git
|
||||||
|
|
||||||
# clone only a specific branch
|
# clone only a specific branch
|
||||||
$ git clone -b master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch
|
$ git clone -b master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch
|
||||||
```
|
```
|
||||||
|
|
||||||
### commit
|
### commit
|
||||||
|
|
||||||
Stores the current contents of the index in a new "commit." This commit contains
|
Stores the current contents of the index in a new "commit." This commit
|
||||||
the changes made and a message created by the user.
|
contains the changes made and a message created by the user.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# commit with a message
|
# commit with a message
|
||||||
@ -383,7 +395,8 @@ $ git pull origin master
|
|||||||
$ git pull
|
$ git pull
|
||||||
|
|
||||||
# Merge in changes from remote branch and rebase
|
# Merge in changes from remote branch and rebase
|
||||||
# branch commits onto your local repo, like: "git pull <remote> <branch>, git rebase <branch>"
|
# branch commits onto your local repo, like: "git pull <remote> <branch>, git
|
||||||
|
# rebase <branch>"
|
||||||
$ git pull origin master --rebase
|
$ git pull origin master --rebase
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -409,8 +422,8 @@ $ git push
|
|||||||
|
|
||||||
### stash
|
### stash
|
||||||
|
|
||||||
Stashing takes the dirty state of your working directory and saves it on a stack
|
Stashing takes the dirty state of your working directory and saves it on a
|
||||||
of unfinished changes that you can reapply at any time.
|
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
|
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
|
from the remote. Since you have dirty (uncommited) changes to some files, you
|
||||||
@ -441,7 +454,8 @@ nothing to commit, working directory clean
|
|||||||
```
|
```
|
||||||
|
|
||||||
You can see what "hunks" you've stashed so far using `git stash list`.
|
You can see what "hunks" you've stashed so far using `git stash list`.
|
||||||
Since the "hunks" are stored in a Last-In-First-Out stack, our most recent change will be at top.
|
Since the "hunks" are stored in a Last-In-First-Out stack, our most recent
|
||||||
|
change will be at top.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git stash list
|
$ git stash list
|
||||||
@ -471,7 +485,8 @@ Now you're ready to get back to work on your stuff!
|
|||||||
|
|
||||||
### rebase (caution)
|
### rebase (caution)
|
||||||
|
|
||||||
Take all changes that were committed on one branch, and replay them onto another branch.
|
Take all changes that were committed on one branch, and replay them onto
|
||||||
|
another branch.
|
||||||
*Do not rebase commits that you have pushed to a public repo*.
|
*Do not rebase commits that you have pushed to a public repo*.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -485,8 +500,8 @@ $ git rebase master experimentBranch
|
|||||||
### reset (caution)
|
### reset (caution)
|
||||||
|
|
||||||
Reset the current HEAD to the specified state. This allows you to undo merges,
|
Reset the current HEAD to the specified state. This allows you to undo merges,
|
||||||
pulls, commits, adds, and more. It's a great command but also dangerous if you don't
|
pulls, commits, adds, and more. It's a great command but also dangerous if you
|
||||||
know what you are doing.
|
don't know what you are doing.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Reset the staging area, to match the latest commit (leaves dir unchanged)
|
# Reset the staging area, to match the latest commit (leaves dir unchanged)
|
||||||
@ -504,11 +519,12 @@ $ git reset 31f2bb1
|
|||||||
# after the specified commit).
|
# after the specified commit).
|
||||||
$ git reset --hard 31f2bb1
|
$ git reset --hard 31f2bb1
|
||||||
```
|
```
|
||||||
|
|
||||||
### revert
|
### revert
|
||||||
|
|
||||||
Revert can be used to undo a commit. It should not be confused with reset which restores
|
Revert can be used to undo a commit. It should not be confused with reset which
|
||||||
the state of a project to a previous point. Revert will add a new commit which is the
|
restores the state of a project to a previous point. Revert will add a new
|
||||||
inverse of the specified commit, thus reverting it.
|
commit which is the inverse of the specified commit, thus reverting it.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Revert a specified commit
|
# Revert a specified commit
|
||||||
@ -550,4 +566,3 @@ $ git rm /pather/to/the/file/HelloWorld.c
|
|||||||
* [Pro Git](http://www.git-scm.com/book/en/v2)
|
* [Pro Git](http://www.git-scm.com/book/en/v2)
|
||||||
|
|
||||||
* [An introduction to Git and GitHub for Beginners (Tutorial)](http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners)
|
* [An introduction to Git and GitHub for Beginners (Tutorial)](http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user