# Git Tutorial
---
[TOP]
## install git
Fool can be installed, not go into here
## registered account https://gitee.com
## Configuration
### (1) Configure git user name and mailbox
git config --global user.name 'your username'
git config --global user.email 'your mailbox'
### (2) Public key configuration
Generating a public key ssh, [Public Key Set] (http://git.mydoc.io/?t=154712) do not always have to enter at the time of submission.
```
# Generated sshkey:
ssh-keygen -t rsa -C "[email protected]"
# Enter three times to generate ssh key
# C: id_rsa and id_rsa.pub will see two files /Users/Administrator/.ssh, which id_rsa is private and not leak out, and id_rsa.pub is the public key can be made public.
1. Locate the id_rsa.pub file (using Notepad to open)
2. Copy the contents inside
3. Paste the text box under the public https://gitee.com/profile/sshkeys inside, just write the title.
```
The first ## uploads
Local projects have to be uploaded to online
### (1) Create Repository
mkdir test // create a new directory in the path do not have Chinese characters!
cd test // switch to the directory
### (2) initialize git
git init
### (3) associated with the local file remote file.
git remote add origin https://gitee.com/xxx/demo.git
README.md file ### (4) github is not in the local directory of the code, the code can be incorporated by the following command
git pull --rebase origin master
After executing the above code you can see native code library file more README.md
### (5) to add local files to git repository, and submit the file to add records
git add . && git commit -m '注释'
### (6) submitted to the local repository to modify the record line (the write command together with the above
git push -u origin master (first written later can be omitted to directly to `git push`)
## The second way to upload
No local project and want to download a remote file
git clone https://gitee.com/xxx/demo.git
------
Well above basic initialization of a project, here is more with the project file.
------
## add files to the local equivalent of svn git repository of +
git add test.txt
## submission of documents to a local git repository
git commit -m 'add test.txt'
```
1. The submission of documents to the equivalent of svn git repository of commit.
2. Parameter `-m` an explanation for this submission, you can enter any meaningful content changes recorded so easy to find from history.
3. You can add multiple files at the same time
```
Modify files in the file write something
## Viewing File Status [prompt message to tell us which files are modified]
git status
## see more content
git diff
And then modify the file, write something in the file
## view the revision history [print the detailed log information] id corresponding version number will be displayed
git log
## We can also view the log in a more concise way, only need to add "--pretty = online" parameter can be
git log --pretty=online
## version rollback
git reset - version number
## record command every time we execute "git reflog"
Go reflog
## undo changes
git checkout --text.txt
## Delete Files
git rm text.txt
```
reference:
1. (深入学习:Windows下Git入门教程)[http://blog.csdn.net/huangyabin001/article/details/35557231]
# (上)是基本操作,必学
# (下)是分支操作,可以作为扩展。
2. 廖雪峰的git入门
```
---
## git和svn的区别
```
1. Git是分布式的,而Svn不是分布的.
相同的是:Git跟Svn一样有自己的集中式版本库和Server端。
不同的是:但Git更倾向于分布式开发,因为每一个开发人员的电脑上都有一个本地仓库,所以即使没有网络也一样可以Commit,查看历史版本记录,创建项 目分支等操作,等网络再次连接上Push到Server端。
2. 版本库:
SVN只能有一个指定中央版本库。当这个中央版本库有问题时,所有工作成员都一起瘫痪直到版本库维修完毕或者新的版本库设立完成。
Git可以有无限个版本库。每一个Git都是一个版本库,区别是它们是否拥有活跃目录(Git Working Tree)。如果主要版本库(例如:置於GitHub的版本库)发生了什麼事,工作成员仍然可以在自己的本地版本库(local repository)提交,等待主要版本库恢复即可。工作成员也可以提交到其他的版本库
3. Git的内容的完整性要优于SVN
4. Git把内容按元数据方式存储,而SVN是按文件.
因为,.git目录是处于你的机器上的一个克隆版的版本库,它拥有中心版本库上所有的东西,例如标签,分支,版本记录等。.git目录的体积大小跟.svn比较,你会发现它们差距很大。
5. Git没有一个全局版本号,而SVN有
6. Git下载下来后,在离线状态下可以看到所有的Log,SVN不可以
7. 分支(Branch)
在SVN,分支是一个完整的目录。且这个目录拥有完整的实际文件。如果工作成员想要开啟新的分支,那将会影响“全世界”.
在git,每个工作成员可以任意在自己的本地版本库开啟无限个分支。举例:当我想尝试破坏自己的程序(安检测试),并且想保留这些被修改的文件供日后使用, 我可以开一个分支,做我喜欢的事。完全不需担心妨碍其他工作成员。只要我不合并及提交到主要版本库,没有一个工作成员会被影响。等到我不需要这个分支时, 我只要把它从我的本地版本库删除即可
8. 提交(Commit)在SVN,当你提交你的完成品时,它将直接记录到中央版本库。当你发现你的完成品存在严重问题时,你已经无法阻止事情的发生了。如果网路中断,你根本没办法提交!而Git的提交完全属於本地版本库的活动。而你只需“推”(git push)到主要版本库即可。Git的“推”其实是在执行“同步”(Sync)。
來源:(话说Svn与Git的区别)[http://www.jianshu.com/p/bfec042349ca]
```