Getting Started with git and common commands

1, git and github introduction

What is Git
Git is a distributed version control system open source, used to treat any small or large projects quickly and efficiently

Version control
CVS / SVN / Git

SVN
client / server

GIT
client / code hosting site (for example: github)

Note 1: The Web site also hosted similar code: github / yard cloud / cloud Ali Source Code Management
Note 2: The similar technology GitLab, but it GitHub there are some differences
GitLab GitHub and Git works as belonging to third parties based development free and open source. Github and similar, can be a registered user to submit any of your code, add SSHKey and so on.
The difference is, GitLab can be deployed on its own server, database and other information are all in their own hands, for collaborative development within the team,
you can not always put wisdom within the team always on someone else's server, right? In simple terms it can be seen as a personal version of the GitLab GitHub.

Git and SVN difference (emphasis record 1/2/3 points)
1, to the center of
GIT is distributed, SVN is not: This is the GIT and other non-distributed version control systems such as SVN, CVS, etc., the core the difference.
2, a copy of any git repository can be used independently as a server
3, there are four states in Git file:
untracked (untrack): Indicates the file is newly added
modified (modified): represents the modified file, but have not yet saved to the git repository.
Has been staging (staged): representation of a modified version of the current file been marked to include in the next snapshot submitted
has been submitted (committed): indicates that the file has been saved in the git repository.
4, other
GIT does not have a global version number, and SVN are: This is by far compared with GIT SVN missing one of the biggest features.
GIT content integrity is superior to SVN: GIT content storage using the SHA-1 hash algorithm. This ensures the integrity of the content of the code, make sure to reduce damage to the repository in the event of disk failure and network issues
5, record snapshots directly, rather than differences in
GIT by the content metadata stored, and SVN is by file: All resource control systems are the meta-information files hidden in a similar .svn, .cvs other folder.
Direct recording snapshot, not a differential
6, direct recording snapshots, rather than differences in
the different branches of GIT and SVN branch, a branch that does not particularly in SVN, is another of a directory in the repository.

3. Practice Operation: github site-related actions

1. Create a warehouse (private libraries and public libraries)

 注1:仓库对应url支持多种协议,最常用的有两种:https/ssh
 注2:github上repository分为public和private
      顾名思义public可以被其他人看到并clone;而private是不能被别人看到的,但是可以被clone,由于是private的,要克隆当然是需要一些强前提条件的,
      不然安全性无法保证,private也就失去了意义。这里把repository创建为private的场景为:自己创建一个私人项目,但是又需要和其他developer一起开发,
      所以,需要developer都能克隆这个private repository,并且都能提交到这个private repository。         
      私有库貌似要收钱钱的,不过这已经是历史了
     			
      微软 Github 收购事件于昨天(2018年06月04日)尘埃落定,微软最终以 75 亿美元正式收购 Github。
      更有网友称这是一桩最滑稽的收购案,世界上最大的闭源公司收购了世界上最大的开源公司。
      新年2019年1月,新的 Github, Github 宣布了两个重大更新
      即现在可以无限制的免费使用 Github 私有仓库,让开发人员更好的使用 GitHub,不过最多只有 3 个免费协作成员。

Github simple to use
to log github website
create public library chz_pub
create private libraries chz_ssm
Here Insert Picture Description
Here Insert Picture Description
test delete warehouse
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

2, download installation Git-20-64-bit.exe

Download and install Git

Download:
https://git-scm.com/downloads

After the download is complete:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
create a Start menu directory name, the default git, no need to modify
Here Insert Picture Description
Editor's choice of using git
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
end of the line conversion line breaks, use the default values
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
to detect the installation is successful, any window or the desktop can be right, can appear the following two options
Here Insert Picture Description

4, Git commonly used commands

Git configuration account and mailbox (native)
Here Insert Picture Description
Git configuration account and mailbox (native)
will be used when installing Git is generally just have to configure the user name and password, because you submit code to the local repository (upload code to the remote repository),
if not it is not configured, when you submit it'll remind you. However, if only clone (ie, download) public projects, you do not even registered - we just created an account for future
fork other items, as well as push our own modifications.

The command line configuration

0.“Git bash here”打开命令窗口
1.查看git的配置列表
git config --list
注1:如果没有配置东西,应该是空的。照着下面步骤配置完成后,你可以再试一下该命令,就会出现一系列配置信息
2.设置用户名/邮箱/密码
git config --global user.name “username”
git config --global user.email “email”
git config --global user.password “password”

咱不需要密码,到时候用ssh key
git config --global user.name " 52hz-my"
git config --global user.email “[email protected]

 注1:全局变量
       --global  表示全局的,即当前用户都有效,该配置会出现在 ~/.gitconfig 文件中,~表示当前用户的目录,
      比如我的是:C:\Users\Administrator\.gitconfig,打开该文件你会发现如下图所示的内容: 
       [user]
   name = xxx
   email = [email protected]
 注2:局部变量
      git config user.name  "username"  
      git config user.email  "email"
      局部是只对当前仓库起效的,它的配置信息会在当前仓库根目录/.git/config文件下
      注意:局部变量覆盖全局变量!!!和编程语言里面的变量关系是一样的。
 注3:删除某个全局配置项
      git config --global --unset user.name

6. git文件状态与工作区域(重点)

git的文件状态是其git核心内容,了解后对后续的操作有莫大的帮助,不同的文件状态又存储在不同的工作区域中。
1.文件状态
git中的文件有以下几种状态
未跟踪(untrack):表示文件为新增加的
已暂存(staged):表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中
已提交(committed):表示文件已保存在git仓库中。
已修改(modified):表示修改了文件,但还没保存到git仓库中。
2.工作区域
按照本地计算机与远程计算机划分,工作区域有以下几种
1)本地计算机
Working Directory(工作目录):即正在编辑的文件状态。文件状态为未跟踪(untrack)和已修改(modified)在此区域内。
Staging Area(暂存区):保存了下次将提交的文件列表信息。文件状态为已暂存(staged)在此区域内。
Repository(本地仓库):提交到本地仓库的文件。
2)远程计算机
Repository(远程仓库):已提交到远程计算机内的文件。
注1:git文件状态与工作区域详情可参考:Here Insert Picture Description

7. 常用命令(重点)

git clone :将远程仓库clone到本地计算机。
git status :展示工作区及暂存区域中不同状态的文件。
git add :将内容从工作目录添加到暂存区。
git commit :所有通过 git add 暂存的文件提交到本地仓库。
git push :将本地仓库的记录提交到远程仓库。
git reset HEAD :从暂存区移除指定文件。
git checkout – :从本地仓库恢复指定文件。
git pull :拉取远程仓库的数据。
git init

8. 实践操作:使用git提交文件至远程仓库(重点)

首先明确大致流程:
1.取得项目的 Git 仓库(有两种方式,本章先介绍第一种)
第一种是从github现有仓库(远程)克隆出新的仓库(本地)
第二种是在工作目录中初始化新的仓库(本地),然后再与一个Github上的仓库(远程)关联
2.在本地的克隆库上进行你所需要的改动,修改文件内容,添加文件等;
3.add,commit,push三部曲。
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
具体步骤:
1.取得项目的Git仓库(从github现有仓库克隆)
此处url改为自己仓库的地址
git clone https://github.com/yanppp999/test1.git

 注1:此命令,会在当前目录下创建一个名为test1的目录,其中包含一个 .git 的目录,用于保存下载下来的所有版本记录。
      如果进入这个新建的 test1 目录,你会看到项目中的所有文件已经在里边了,准备好后续的开发和使用。
 注2:克隆仓库的命令格式为 git clone [url],Git支持多种协议,包括https,但通过ssh支持的原生git协议速度最快    
      git clone [email protected]:fsliurujie/test.git          --SSH协议
      git clone git://github.com/fsliurujie/test.git        --GIT协议
      git clone https://github.com/fsliurujie/test.git      --HTTPS协议 
      提问:那平时使用哪个协议最好呢???
 注3:你熟悉其他的 VCS 比如 Subversion,你可能已经注意到这里使用的是 clone 而不是 checkout。这是个非常重要的差别,
      Git 收取的是项目历史的所有数据(每一个文件的每一个版本),服务器上有的数据克隆之后本地也都有了。实际上,
      即便服务器的磁盘发生故障,用任何一个克隆出来的客户端都可以重建服务器上的仓库,回到当初克隆时的状态 
 注4:如果希望在克隆的时候,自己定义要新建的项目目录名称,可以在上面的命令末尾指定新的名字
      git clone https://github.com/yanppp999/test1.git mytest1
 注5:如何查看.git目录(默认为隐藏文件夹)
      window菜单:“查看”->“选项”->选择,选项卡“查看”->勾中“显示隐藏的文件、文件夹和驱动器”

Here Insert Picture Description
Here Insert Picture Description

Published 66 original articles · won praise 4 · Views 961

Guess you like

Origin blog.csdn.net/weixin_45346741/article/details/103410553